package com.ymatou.iapi.trading.operate.testcase;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.stream.Collectors;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.optrade.parameter.utill.Utils;
import com.ymatou.iapi.optrade.service.PrepaidCardService;
import com.ymatou.iapi.settlement.parameter.SettleSellerIncomeAndChargeCommissionBean;
import com.ymatou.iapi.settlement.service.SettleSellerIncomeAndChargeCommissionCall;
import com.ymatou.iapi.trading.operate.parameter.Order;
import com.ymatou.iapi.trading.operate.parameter.OrderInfoPo;
import com.ymatou.iapi.trading.operate.parameter.PlaceOrderResp;
import com.ymatou.iapi.trading.operate.parameter.PlaceOrderService;
import com.ymatou.iapi.trading.operate.parameter.req.ApplySalesRefundRequestBean;
import com.ymatou.iapi.trading.operate.parameter.req.ApproveRefundBillReq;
import com.ymatou.iapi.trading.operate.parameter.req.SalesRefundInfoBean;
import com.ymatou.iapi.trading.operate.service.ApplySalesRefundRequestCall;
import com.ymatou.iapi.trading.operate.service.SalesRefundSuccessRequestCall;
import com.ymt.base.YmatouEasyCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.AccountCallServiceV2;
import com.ymttest.business.service.AccountCallServiceV2;
import com.ymttest.business.service.OrderCallService;
import com.ymttest.business.service.PaymentProxyCallService;
import com.ymttest.database.model.YmtAccountEntry;
import com.ymttest.database.model.YmtRefundBill;
import com.ymttest.database.model.YmtRefundProduct;
import com.ymttest.database.model.YmtSettlementInvoice;
import com.ymttest.database.sqlwapper.AccountDefaultWapper;
import com.ymttest.database.sqlwapper.DefaultWapper;
import com.ymttest.database.sqlwapper.YmtRefundWapper;
import com.ymttest.database.sqlwapper.YmtSettlementInvoiceWapper;
import com.ymttest.utils.DataUtil;

public class Ts_SalesRefundSuccessRequest {
	private static ApproveRefundBillReq salesrefundsuccessrequestBean;
	private static SalesRefundSuccessRequestCall salesrefundsuccessrequestCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("退货/退款成功完成接口");
	}

	@Before
	public void caseUp() {
		salesrefundsuccessrequestBean = new ApproveRefundBillReq();
		salesrefundsuccessrequestCall = new SalesRefundSuccessRequestCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(salesrefundsuccessrequestCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	/***
	 *  申请将该订单下所有商品全款退款
	 * @param orderId
	 * @return
	 */
	public static ApplySalesRefundRequestBean applyRefundAllProduct(
			Integer orderId) {
		// 申请退款
		ApplySalesRefundRequestBean applysalesrefundrequestBean = new ApplySalesRefundRequestBean();
		ApplySalesRefundRequestCall applysalesrefundrequestCall = new ApplySalesRefundRequestCall();
		try {

			applysalesrefundrequestBean = new OrderCallService()
					.applySalesRefundRequestInJavaBean(orderId);
			applysalesrefundrequestCall.setData(false,
					applysalesrefundrequestBean);
			applysalesrefundrequestCall.callService();

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return applysalesrefundrequestBean;
	}

	/**
	 * 确认收货后，给商家结算订单收入
	 * @param orderId
	 */
	private void settlesellerIncome(long orderId) {

		SettleSellerIncomeAndChargeCommissionBean settlesellerincomeandchargecommissionBean = new SettleSellerIncomeAndChargeCommissionBean();
		SettleSellerIncomeAndChargeCommissionCall settlesellerincomeandchargecommissionCall = new SettleSellerIncomeAndChargeCommissionCall();
		settlesellerincomeandchargecommissionBean.setOrderId(orderId);
		settlesellerincomeandchargecommissionCall
				.setData(settlesellerincomeandchargecommissionBean);
		try {
			settlesellerincomeandchargecommissionCall.callService();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 *  接单之后，所有订单上商品所有款都退完后，订单变更为用户取消，给商家结算剩余金额
	 * @param orderId
	 */
	private void settleLeftAmtAfterCancelled(Integer orderId) {

		YmatouEasyCall settleLeftAmtAfterCancelled = new YmatouEasyCall("",
				"POST", "JSON");
		String json = "{\"orderId\":" + orderId + "}";

		settleLeftAmtAfterCancelled
				.setUrl("http://settlement.iapi.ymatou.com/api/settleLeftAmtAfterCancelled");

		settleLeftAmtAfterCancelled.setData(json);
		Logger.comment("接单后，退货退完后，订单为用户取消，给商家结算剩余金额");
		try {
			settleLeftAmtAfterCancelled.callService();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();

		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SalesRefundSuccessRequest_000() {
		Logger.start(true, "test");

		Logger.info(Integer.MAX_VALUE);

	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SalesRefundSuccessRequest_001() {
		Logger.start(true, "余额全款支付。确认收货前,订单多个商品依次全部全款退款");
		try {

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder9();;

			Order order = placeOrderResp.getOrderList().get(0);

			int orderId = order.getOrderId();
			int sellerId = order.getSellerId();

			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal amount = placeOrderResp.getPayAmount();// 支付金额

			OrderCallService orderCallService = new OrderCallService();

			for (OrderInfoPo orderInfoPo : order.getOrderInfoList()) {

				String proId = orderInfoPo.getProductId();
				String calId = orderInfoPo.getCatalogId();

				int stockNum = Ts_PlaceOrder.getStockNum(proId, calId, false);

				Logger.comment(String.format(
						"proId：%s,calalogId:%s 下单之后的库存:%s", proId, calId,
						stockNum));
			}

			// 付款
			orderCallService.orderPayRequest(userId, amount, tradingId);
			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 申请退款
			applyRefundAllProduct(orderId);

			salesrefundsuccessrequestBean.setOperatorInfo("autotest");
			salesrefundsuccessrequestBean.setOrderId(orderId);

			salesrefundsuccessrequestBean.setRefundBillNo("TH0"
					+ String.valueOf(orderId));

			salesrefundsuccessrequestCall
					.setData(salesrefundsuccessrequestBean);
			Logger.comment("退该订单号" + orderId + "第一件商品");
			salesrefundsuccessrequestCall.callService();
			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");
			salesrefundsuccessrequestBean.setOrderId(orderId);
			salesrefundsuccessrequestBean.setRefundBillNo("TH1"
					+ String.valueOf(orderId));
			salesrefundsuccessrequestCall
					.setData(salesrefundsuccessrequestBean);
			Logger.comment("退该订单号" + orderId + "第二件商品");

			// Thread.sleep(5000);
			salesrefundsuccessrequestCall.callService();

			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");
			DefaultWapper defaultWapper = new DefaultWapper();

			if (salesrefundsuccessrequestCall.getReturnData().equals("ok")) {
				// 数据库验
				Map m = new HashMap();

				m.put("orderId", orderId);

				// 查询交易退款结算表
				List<YmtSettlementInvoice> settlementInvoiceList = new YmtSettlementInvoiceWapper()
						.selectYmtSettlementInvoice(m);

				settlementInvoiceList = settlementInvoiceList.stream()
						.filter(item ->

						item.getBusinessType() != 14

						).collect(Collectors.toList());

				// 订单商品表
				List<Map> orderInfoList = defaultWapper
						.selectOrderInfoByOderId(orderId);
				// 订单主表
				List<Map> ymtOrders = defaultWapper
						.selectOrderByOderId(orderId);
				// ymtOrderState 表
				List<Map> ymtOrderState = defaultWapper
						.selectOrderStateByOderId(orderId);

				YmtRefundWapper ymtRefund = new YmtRefundWapper();

				// m.put("refundBillNo", refundBillNo);

				for (int i = 0; i < orderInfoList.size(); i++) {
					// 订单退货记录
					YmtRefundBill refundBill = ymtRefund.selectRefundBill(m)
							.get(i);
					// 退货的商品记录
					YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(
							m).get(i);
					// 退款退货商品 catalogid
					String catalogId = refundPro.getCatalogId();
					// 商品使用的平台优惠券
					BigDecimal productYmtCouponValue = BigDecimal.ZERO;
					for (Map m1 : orderInfoList) {
						if (((String) m1.get("sCatalogId")).equals(catalogId)) {
							productYmtCouponValue = (BigDecimal) m1
									.get("fYmtCouponAmount");
						}
					}
					Logger.comment("校验订单号" + orderId + "第" + (i + 1) + "件商品");
					Logger.comment("校验Ymt_RefundBill表");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals("TH" + i + String.valueOf(orderId),
							refundBill.getRefundBillNo(), "验证RefundBillNo");
					Logger.verifyEquals(1, refundBill.getRefundStatus(),
							"验证RefundStatus");
					Logger.verifyEquals(1, refundBill.getSettlementStatus(),
							"验证SettlementStatus");
					Logger.verifyEquals(10, refundBill.getSalesRefundStatus(),
							"验证SalesRefundStatus");
					Logger.verifyEquals(1, refundBill.getRefundType(),
							"验证RefundType");
					Logger.verifyEquals("autotest refund",
							refundBill.getReason(), "验证Reason");
					// 退的平台优惠券
					Logger.verifyEquals(productYmtCouponValue,
							refundBill.getSettlementAmountOfCoupon(),
							"验证SettlementAmountOfCoupon");
					Logger.verifyEquals(sellerId, refundBill.getSellerId(),
							"验证SellerId");
					Logger.verifyEquals(userId, refundBill.getBuyerId(),
							"验证BuyerId");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.comment("校验Ymt_RefundProduct表");
					Logger.verifyEquals(orderId, refundPro.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals("TH" + i + String.valueOf(orderId),
							refundPro.getRefundBillNo(), "验证RefundBillNo");

					if (settlementInvoiceList.get(i).getBusinessNo()
							.equals(refundPro.getRefundBillNo())) {

						Logger.comment("校验Ymt_SettlementInvoice表");

						Logger.verifyEquals("TH" + i + String.valueOf(orderId),
								settlementInvoiceList.get(i).getBusinessNo(),
								"验证BusinessNo");

						Logger.verifyEquals(2, settlementInvoiceList.get(i)
								.getBusinessType(), "验证BusinessType");

						Logger.verifyEquals(orderId,
								settlementInvoiceList.get(i).getOrderId(),
								"验证OrderId");

						Logger.verifyEquals((settlementInvoiceList.get(i)
								.getCashAmount()).add(settlementInvoiceList
								.get(i).getCouponAmount()),
								settlementInvoiceList.get(i).getTotalAmount(),
								"验证TotalAmount");

						Logger.verifyEquals(refundBill.getRefundAmount(),
								settlementInvoiceList.get(i).getCashAmount(),
								"验证CashAmount");
						// 退的ymt 平台优惠券
						Logger.verifyEquals(productYmtCouponValue,
								settlementInvoiceList.get(i).getCouponAmount(),
								"验证CouponAmount");

						Logger.verifyEquals(sellerId, settlementInvoiceList
								.get(i).getSellerId(), "验证SellerId");
						Logger.verifyEquals("退款结算", settlementInvoiceList
								.get(i).getRemark(), "验证Remark");
						Logger.verifyEquals(1, settlementInvoiceList.get(i)
								.getSettlementStatus(), "验证SettlementStatus");
						Logger.verifyEquals(1, settlementInvoiceList.get(i)
								.getSettlementUser(), "验证SettlementUser");
						Logger.verifyEquals(null, settlementInvoiceList.get(i)
								.getProcessResult(), "验证ProcessResult");
						Logger.verifyEquals(refundBill.getRefundAmount(),
								settlementInvoiceList.get(i)
										.getfAccountAmount(),
								"验证fAccountAmount");
						Logger.verifyEquals(BigDecimal.ZERO.setScale(2),
								settlementInvoiceList.get(i)
										.getfThirdPartyAmount(),
								"验证fThirdPartyAmount");
						Logger.comment("校验ymt_orderinfo表");
						Logger.verifyEquals(10, (Integer) orderInfoList.get(i)
								.get("iProductRefundStatus"),
								"验证iProductRefundStatus");
						// 资金流水表
						List<YmtAccountEntry> ymtActList = new AccountDefaultWapper()
								.selectAccountEntryByOriginalNo(settlementInvoiceList
										.get(i).getBusinessNo());
						List<YmtAccountEntry> userActList = ymtActList.stream()
								.filter(act -> act.getUserid() == userId)
								.collect(Collectors.toList());

						Logger.verifyEquals((settlementInvoiceList.get(i)
								.getfAccountAmount())
								.compareTo(BigDecimal.ZERO) > 0 ? 1 : 0,
								userActList.size(), "验证用户账户流水表记录");
						if (userActList.size() > 0) {
							Logger.comment("校验Ymt_AccountEntry表");
							Logger.verifyEquals(settlementInvoiceList.get(i)
									.getfAccountAmount(), userActList.get(0)
									.getAmount(), "验证用户账户流水表Amount");
						}
						List<YmtAccountEntry> sellerActList = ymtActList
								.stream()
								.filter(act -> act.getUserid() == sellerId)
								.collect(Collectors.toList());
						Logger.verifyEquals(0, sellerActList.size(),
								"验证商家账户流水表记录");
					}
				}
				Logger.comment("校验ymt_orders表");
				Logger.verifyEquals(12,
						(Integer) ymtOrders.get(0).get("iTradingStatus"),
						"验证iTradingStatus");
				Logger.verifyEquals(null,
						ymtOrders.get(0).get("iSalesRefundStatus"),
						"验证iSalesRefundStatus");

				Logger.comment("校验ymt_orderstate表");
				Logger.verifyEquals(
						settlementInvoiceList.stream()
								.map(account -> account.getCashAmount())
								.reduce(BigDecimal.ZERO, BigDecimal::add),

						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountOfCash"),
						"验证fRefundedAmountOfCash");
				Logger.verifyEquals(
						settlementInvoiceList.stream()
								.map(account -> account.getfAccountAmount())
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountToAccount"),
						"验证fRefundedAmountToAccount");
				Logger.verifyEquals(null, (BigDecimal) ymtOrderState.get(0)
						.get("fRefundedPaidAmountToThirdParty"),
						"验证fRefundedPaidAmountToThirdParty");

				for (OrderInfoPo orderInfoPo : order.getOrderInfoList()) {

					String proId = orderInfoPo.getProductId();
					String calId = orderInfoPo.getCatalogId();

					int stockNum = Ts_PlaceOrder.getStockNum(proId, calId,
							false);

					Logger.comment(String.format(
							"proId：%s,calalogId:%s 退货退款之后发送返库存之后的库存:%s", proId,
							calId, stockNum));
				}

			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SalesRefundSuccessRequest_002() {
		Logger.start(true, "全部第三方支付宝支付。确认收货前,订单多个商品依次全部全款退款");
		try {

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder4();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			OrderCallService orderCallService = new OrderCallService();

			// 用余额支付金额
			BigDecimal blanceAmout = BigDecimal.ZERO;
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "13";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payType);
			// 支付网关支付回调交易
			PaymentProxyCallService.notifyCall(payType,
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			// 等待支付网关异步处理
			Thread.sleep(5000);
			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 申请退款
			applyRefundAllProduct(orderId);
			salesrefundsuccessrequestBean.setOperatorInfo("autotest");
			salesrefundsuccessrequestBean.setOrderId(orderId);
			salesrefundsuccessrequestBean.setRefundBillNo("TH0"
					+ String.valueOf(orderId));
			salesrefundsuccessrequestCall
					.setData(salesrefundsuccessrequestBean);
			Logger.comment("退该订单号" + orderId + "第一件商品");
			salesrefundsuccessrequestCall.callService();
			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");
			salesrefundsuccessrequestBean.setOrderId(orderId);
			salesrefundsuccessrequestBean.setRefundBillNo("TH1"
					+ String.valueOf(orderId));
			salesrefundsuccessrequestCall
					.setData(salesrefundsuccessrequestBean);
			Logger.comment("退该订单号" + orderId + "第二件商品");
			salesrefundsuccessrequestCall.callService();
			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");
			// 支付网关退款回调交易
			PaymentProxyCallService.refundNotifyCall(payType,
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			Thread.sleep(5000);

			DefaultWapper defaultWapper = new DefaultWapper();
			if (salesrefundsuccessrequestCall.getReturnData().equals("ok")) {

				// 数据库验
				// 查询交易退款结算表
				Map m = new HashMap();

				m.put("orderId", orderId);

				// 查询交易退款结算表
				List<YmtSettlementInvoice> settlementInvoiceList = new YmtSettlementInvoiceWapper()
						.selectYmtSettlementInvoice(m);

				settlementInvoiceList = settlementInvoiceList.stream()
						.filter(item ->

						item.getBusinessType() != 14

						).collect(Collectors.toList());
				// 订单商品表
				List<Map> orderInfoList = defaultWapper
						.selectOrderInfoByOderId(orderId);
				// 订单主表
				List<Map> ymtOrders = defaultWapper
						.selectOrderByOderId(orderId);
				// ymtOrderState 表
				List<Map> ymtOrderState = defaultWapper
						.selectOrderStateByOderId(orderId);
				YmtRefundWapper ymtRefund = new YmtRefundWapper();

				// m.put("refundBillNo", refundBillNo);
				for (int i = 0; i < orderInfoList.size(); i++) {
					// 订单退货记录
					YmtRefundBill refundBill = ymtRefund.selectRefundBill(m)
							.get(i);
					// 退货的商品记录
					YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(
							m).get(i);
					// 退款退货商品 catalogid
					String catalogId = refundPro.getCatalogId();
					// 商品使用的平台优惠券
					BigDecimal productYmtCouponValue = BigDecimal.ZERO;
					for (Map m1 : orderInfoList) {
						if (((String) m1.get("sCatalogId")).equals(catalogId)) {
							productYmtCouponValue = (BigDecimal) m1
									.get("fYmtCouponAmount");
						}
					}
					Logger.comment("校验订单号" + orderId + "第" + (i + 1) + "件商品");
					Logger.comment("校验Ymt_RefundBill表");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals("TH" + i + String.valueOf(orderId),
							refundBill.getRefundBillNo(), "验证RefundBillNo");
					Logger.verifyEquals(1, refundBill.getRefundStatus(),
							"验证RefundStatus");
					Logger.verifyEquals(1, refundBill.getSettlementStatus(),
							"验证SettlementStatus");
					Logger.verifyEquals(10, refundBill.getSalesRefundStatus(),
							"验证SalesRefundStatus");
					Logger.verifyEquals(1, refundBill.getRefundType(),
							"验证RefundType");
					Logger.verifyEquals("autotest refund",
							refundBill.getReason(), "验证Reason");
					// 退的平台优惠券
					Logger.verifyEquals(productYmtCouponValue,
							refundBill.getSettlementAmountOfCoupon(),
							"验证SettlementAmountOfCoupon");
					Logger.verifyEquals(sellerId, refundBill.getSellerId(),
							"验证SellerId");
					Logger.verifyEquals(userId, refundBill.getBuyerId(),
							"验证BuyerId");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.comment("校验Ymt_RefundProduct表");
					Logger.verifyEquals(orderId, refundPro.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals("TH" + i + String.valueOf(orderId),
							refundPro.getRefundBillNo(), "验证RefundBillNo");
					if (settlementInvoiceList.get(i).getBusinessNo()
							.equals(refundPro.getRefundBillNo())) {
						Logger.comment("校验Ymt_SettlementInvoice表");

						Logger.verifyEquals("TH" + i + String.valueOf(orderId),
								settlementInvoiceList.get(i).getBusinessNo(),
								"验证BusinessNo");
						Logger.verifyEquals(2, settlementInvoiceList.get(i)
								.getBusinessType(), "验证BusinessType");
						Logger.verifyEquals(orderId,
								settlementInvoiceList.get(i).getOrderId(),
								"验证OrderId");
						Logger.verifyEquals((settlementInvoiceList.get(i)
								.getCashAmount()).add(settlementInvoiceList
								.get(i).getCouponAmount()),
								settlementInvoiceList.get(i).getTotalAmount(),
								"验证TotalAmount");
						Logger.verifyEquals(refundBill.getRefundAmount(),
								settlementInvoiceList.get(i).getCashAmount(),
								"验证CashAmount");
						// 退的ymt 平台优惠券
						Logger.verifyEquals(productYmtCouponValue,
								settlementInvoiceList.get(i).getCouponAmount(),
								"验证CouponAmount");
						Logger.verifyEquals(sellerId, settlementInvoiceList
								.get(i).getSellerId(), "验证SellerId");
						Logger.verifyEquals("退款结算", settlementInvoiceList
								.get(i).getRemark(), "验证Remark");
						Logger.verifyEquals(1, settlementInvoiceList.get(i)
								.getSettlementStatus(), "验证SettlementStatus");
						Logger.verifyEquals(1, settlementInvoiceList.get(i)
								.getSettlementUser(), "验证SettlementUser");
						Logger.verifyEquals(null, settlementInvoiceList.get(i)
								.getProcessResult(), "验证ProcessResult");
						Logger.comment("校验ymt_orderinfo表");
						Logger.verifyEquals(10, (Integer) orderInfoList.get(i)
								.get("iProductRefundStatus"),
								"验证iProductRefundStatus");
						// 资金流水表
						List<YmtAccountEntry> ymtActList = new AccountDefaultWapper()
								.selectAccountEntryByOriginalNo(settlementInvoiceList
										.get(i).getBusinessNo());
						List<YmtAccountEntry> userActList = ymtActList.stream()
								.filter(act -> act.getUserid() == userId)
								.collect(Collectors.toList());
						Logger.verifyEquals(((BigDecimal) settlementInvoiceList
								.get(i).getfAccountAmount())
								.compareTo(BigDecimal.ZERO) > 0 ? 1 : 0,
								userActList.size(), "验证用户账户流水表记录");
						List<YmtAccountEntry> sellerActList = ymtActList
								.stream()
								.filter(act -> act.getUserid() == sellerId)
								.collect(Collectors.toList());
						Logger.verifyEquals(0, sellerActList.size(),
								"验证商家账户流水表记录");
					}
				}
				Logger.comment("校验ymt_orders表");
				Logger.verifyEquals(12,
						(Integer) ymtOrders.get(0).get("iTradingStatus"),
						"验证iTradingStatus");
				Logger.verifyEquals(null,
						ymtOrders.get(0).get("iSalesRefundStatus"),
						"验证iSalesRefundStatus");
				Logger.comment("校验ymt_orderstate表");
				Logger.verifyEquals(
						settlementInvoiceList.stream()
								.map(account -> account.getCashAmount())
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountOfCash"),
						"验证fRefundedAmountOfCash");
				Logger.verifyEquals(null,
						ymtOrderState.get(0).get("fRefundedAmountToAccount"),
						"验证fRefundedAmountToAccount");

				Logger.verifyEquals(

						settlementInvoiceList.stream()

						.map(account -> account.getfThirdPartyAmount())
								.reduce(BigDecimal.ZERO, BigDecimal::add),

						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedPaidAmountToThirdParty"),
						"验证fRefundedPaidAmountToThirdParty");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SalesRefundSuccessRequest_003() {
		Logger.start(true, "余额+第三方支付宝组合支付。确认收货前,订单多个商品依次全部全款退款");
		try {
			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder4();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			OrderCallService orderCallService = new OrderCallService();

			// 用余额支付金额
			BigDecimal blanceAmout = new BigDecimal(47);
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "13";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payType);
			// 支付网关支付回调交易
			PaymentProxyCallService.notifyCall(payType,
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			// 等待支付网关异步处理
			Thread.sleep(5000);
			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 申请退款
			applyRefundAllProduct(orderId);

			salesrefundsuccessrequestBean.setOperatorInfo("autotest");
			salesrefundsuccessrequestBean.setOrderId(orderId);
			salesrefundsuccessrequestBean.setRefundBillNo("TH0"
					+ String.valueOf(orderId));
			salesrefundsuccessrequestCall
					.setData(salesrefundsuccessrequestBean);
			Logger.comment("退该订单号" + orderId + "第一件商品");
			salesrefundsuccessrequestCall.callService();

			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");
			salesrefundsuccessrequestBean.setOrderId(orderId);
			salesrefundsuccessrequestBean.setRefundBillNo("TH1"
					+ String.valueOf(orderId));
			salesrefundsuccessrequestCall
					.setData(salesrefundsuccessrequestBean);
			Logger.comment("退该订单号" + orderId + "第二件商品");
			salesrefundsuccessrequestCall.callService();
			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");

			// 支付网关退款回调交易
			PaymentProxyCallService.refundNotifyCall(payType,
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			Thread.sleep(5000);

			DefaultWapper defaultWapper = new DefaultWapper();
			if (salesrefundsuccessrequestCall.getReturnData().equals("ok")) {

				// 数据库验
				Map m = new HashMap();

				m.put("orderId", orderId);

				// 查询交易退款结算表
				List<YmtSettlementInvoice> settlementInvoiceList = new YmtSettlementInvoiceWapper()
						.selectYmtSettlementInvoice(m);

				settlementInvoiceList = settlementInvoiceList.stream()
						.filter(item ->

						item.getBusinessType() != 14

						).collect(Collectors.toList());
				// 订单商品表
				List<Map> orderInfoList = defaultWapper
						.selectOrderInfoByOderId(orderId);
				// 订单主表
				List<Map> ymtOrders = defaultWapper
						.selectOrderByOderId(orderId);
				// ymtOrderState 表
				List<Map> ymtOrderState = defaultWapper
						.selectOrderStateByOderId(orderId);
				YmtRefundWapper ymtRefund = new YmtRefundWapper();

				// m.put("refundBillNo", refundBillNo);
				for (int i = 0; i < orderInfoList.size(); i++) {
					// 订单退货记录
					YmtRefundBill refundBill = ymtRefund.selectRefundBill(m)
							.get(i);
					// 退货的商品记录
					YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(
							m).get(i);
					// 退款退货商品 catalogid
					String catalogId = refundPro.getCatalogId();
					// 商品使用的平台优惠券
					BigDecimal productYmtCouponValue = BigDecimal.ZERO;
					for (Map m1 : orderInfoList) {
						if (((String) m1.get("sCatalogId")).equals(catalogId)) {
							productYmtCouponValue = (BigDecimal) m1
									.get("fYmtCouponAmount");
						}
					}
					Logger.comment("校验订单号" + orderId + "第" + (i + 1) + "件商品");
					Logger.comment("校验Ymt_RefundBill表");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals("TH" + i + String.valueOf(orderId),
							refundBill.getRefundBillNo(), "验证RefundBillNo");
					Logger.verifyEquals(1, refundBill.getRefundStatus(),
							"验证RefundStatus");
					Logger.verifyEquals(1, refundBill.getSettlementStatus(),
							"验证SettlementStatus");
					Logger.verifyEquals(10, refundBill.getSalesRefundStatus(),
							"验证SalesRefundStatus");
					Logger.verifyEquals(1, refundBill.getRefundType(),
							"验证RefundType");
					Logger.verifyEquals("autotest refund",
							refundBill.getReason(), "验证Reason");
					// 退的平台优惠券
					Logger.verifyEquals(productYmtCouponValue,
							refundBill.getSettlementAmountOfCoupon(),
							"验证SettlementAmountOfCoupon");
					Logger.verifyEquals(sellerId, refundBill.getSellerId(),
							"验证SellerId");
					Logger.verifyEquals(userId, refundBill.getBuyerId(),
							"验证BuyerId");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.comment("校验Ymt_RefundProduct表");
					Logger.verifyEquals(orderId, refundPro.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals("TH" + i + String.valueOf(orderId),
							refundPro.getRefundBillNo(), "验证RefundBillNo");
					if (settlementInvoiceList.get(i).getBusinessNo()
							.equals(refundPro.getRefundBillNo())) {
						Logger.comment("校验Ymt_SettlementInvoice表");

						Logger.verifyEquals("TH" + i + String.valueOf(orderId),
								settlementInvoiceList.get(i).getBusinessNo(),
								"验证BusinessNo");
						Logger.verifyEquals(2, settlementInvoiceList.get(i)
								.getBusinessType(), "验证BusinessType");
						Logger.verifyEquals(orderId,
								settlementInvoiceList.get(i).getOrderId(),
								"验证OrderId");
						Logger.verifyEquals((settlementInvoiceList.get(i)
								.getCashAmount()).add(settlementInvoiceList
								.get(i).getCouponAmount()),
								settlementInvoiceList.get(i).getTotalAmount(),
								"验证TotalAmount");
						Logger.verifyEquals(refundBill.getRefundAmount(),
								settlementInvoiceList.get(i).getCashAmount(),
								"验证CashAmount");
						// 退的ymt 平台优惠券
						Logger.verifyEquals(productYmtCouponValue,
								settlementInvoiceList.get(i).getCouponAmount(),
								"验证CouponAmount");
						Logger.verifyEquals(sellerId, settlementInvoiceList
								.get(i).getSellerId(), "验证SellerId");
						Logger.verifyEquals("退款结算", settlementInvoiceList
								.get(i).getRemark(), "验证Remark");
						Logger.verifyEquals(1, settlementInvoiceList.get(i)
								.getSettlementStatus(), "验证SettlementStatus");
						Logger.verifyEquals(1, settlementInvoiceList.get(i)
								.getSettlementUser(), "验证SettlementUser");
						Logger.verifyEquals(null, settlementInvoiceList.get(i)
								.getProcessResult(), "验证ProcessResult");
						Logger.comment("校验ymt_orderinfo表");
						Logger.verifyEquals(10, (Integer) orderInfoList.get(i)
								.get("iProductRefundStatus"),
								"验证iProductRefundStatus");
						// 资金流水表
						List<YmtAccountEntry> ymtActList = new AccountDefaultWapper()
								.selectAccountEntryByOriginalNo(settlementInvoiceList
										.get(i).getBusinessNo());
						List<YmtAccountEntry> userActList = ymtActList.stream()
								.filter(act -> act.getUserid() == userId)
								.collect(Collectors.toList());
						Logger.verifyEquals((settlementInvoiceList.get(i)
								.getfAccountAmount())
								.compareTo(BigDecimal.ZERO) > 0 ? 1 : 0,
								userActList.size(), "验证用户账户流水表记录");
						if (userActList.size() > 0) {
							Logger.comment("校验Ymt_AccountEntry表");
							Logger.verifyEquals(
									(BigDecimal) settlementInvoiceList.get(i)
											.getfAccountAmount(), userActList
											.get(0).getAmount(),
									"验证用户账户流水表Amount");
						}
						List<YmtAccountEntry> sellerActList = ymtActList
								.stream()
								.filter(act -> act.getUserid() == sellerId)
								.collect(Collectors.toList());
						Logger.verifyEquals(0, sellerActList.size(),
								"验证商家账户流水表记录");

					}
				}
				Logger.comment("校验ymt_orders表");
				Logger.verifyEquals(12,
						(Integer) ymtOrders.get(0).get("iTradingStatus"),
						"验证iTradingStatus");
				Logger.verifyEquals(null,
						ymtOrders.get(0).get("iSalesRefundStatus"),
						"验证iSalesRefundStatus");
				Logger.comment("校验ymt_orderstate表");

				Logger.verifyEquals(
						settlementInvoiceList.stream()
								.map(account -> account.getCashAmount())
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountOfCash"),
						"验证fRefundedAmountOfCash");

				Logger.verifyEquals(
						settlementInvoiceList.stream()
								.map(account -> account.getfAccountAmount())
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						ymtOrderState.get(0).get("fRefundedAmountToAccount"),
						"验证fRefundedAmountToAccount");

				Logger.verifyEquals(
						settlementInvoiceList
								.stream()
								.map(account -> (BigDecimal) account
										.getfThirdPartyAmount())
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedPaidAmountToThirdParty"),
						"验证fRefundedPaidAmountToThirdParty");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SalesRefundSuccessRequest_004() {
		Logger.start(true, "全部第三方微信支付。确认收货前,订单多个商品依次全部全款退款");
		try {

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder4();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			OrderCallService orderCallService = new OrderCallService();

			// 用余额支付金额
			BigDecimal blanceAmout = BigDecimal.ZERO;
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "15";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payType);
			// 支付网关支付回调交易
			PaymentProxyCallService.notifyCall(payType,
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			// 等待支付网关异步处理
			Thread.sleep(5000);
			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 申请退款
			applyRefundAllProduct(orderId);
			salesrefundsuccessrequestBean.setOperatorInfo("autotest");
			salesrefundsuccessrequestBean.setOrderId(orderId);
			salesrefundsuccessrequestBean.setRefundBillNo("TH0"
					+ String.valueOf(orderId));
			salesrefundsuccessrequestCall
					.setData(salesrefundsuccessrequestBean);
			Logger.comment("退该订单号" + orderId + "第一件商品");
			salesrefundsuccessrequestCall.callService();
			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");
			salesrefundsuccessrequestBean.setOrderId(orderId);
			salesrefundsuccessrequestBean.setRefundBillNo("TH1"
					+ String.valueOf(orderId));
			salesrefundsuccessrequestCall
					.setData(salesrefundsuccessrequestBean);
			Logger.comment("退该订单号" + orderId + "第二件商品");
			salesrefundsuccessrequestCall.callService();
			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");

			// 支付网关退款回调交易
			PaymentProxyCallService.refundNotifyCall(payType,
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			Thread.sleep(5000);

			DefaultWapper defaultWapper = new DefaultWapper();
			if (salesrefundsuccessrequestCall.getReturnData().equals("ok")) {
				// 数据库验
				// 查询交易退款结算表
				List<Map> settlementInvoiceList = defaultWapper
						.selectYmtSettlementInvoice(orderId);
				// 订单商品表
				List<Map> orderInfoList = defaultWapper
						.selectOrderInfoByOderId(orderId);
				// 订单主表
				List<Map> ymtOrders = defaultWapper
						.selectOrderByOderId(orderId);
				// ymtOrderState 表
				List<Map> ymtOrderState = defaultWapper
						.selectOrderStateByOderId(orderId);
				YmtRefundWapper ymtRefund = new YmtRefundWapper();
				Map m = new HashMap();

				m.put("orderId", orderId);

				// m.put("refundBillNo", refundBillNo);
				for (int i = 0; i < orderInfoList.size(); i++) {
					// 订单退货记录
					YmtRefundBill refundBill = ymtRefund.selectRefundBill(m)
							.get(i);
					// 退货的商品记录
					YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(
							m).get(i);
					// 退款退货商品 catalogid
					String catalogId = refundPro.getCatalogId();
					// 商品使用的平台优惠券
					BigDecimal productYmtCouponValue = BigDecimal.ZERO;
					for (Map m1 : orderInfoList) {
						if (((String) m1.get("sCatalogId")).equals(catalogId)) {
							productYmtCouponValue = (BigDecimal) m1
									.get("fYmtCouponAmount");
						}
					}
					Logger.comment("校验订单号" + orderId + "第" + (i + 1) + "件商品");
					Logger.comment("校验Ymt_RefundBill表");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals("TH" + i + String.valueOf(orderId),
							refundBill.getRefundBillNo(), "验证RefundBillNo");
					Logger.verifyEquals(1, refundBill.getRefundStatus(),
							"验证RefundStatus");
					Logger.verifyEquals(1, refundBill.getSettlementStatus(),
							"验证SettlementStatus");
					Logger.verifyEquals(10, refundBill.getSalesRefundStatus(),
							"验证SalesRefundStatus");
					Logger.verifyEquals(1, refundBill.getRefundType(),
							"验证RefundType");
					Logger.verifyEquals("autotest refund",
							refundBill.getReason(), "验证Reason");
					// 退的平台优惠券
					Logger.verifyEquals(productYmtCouponValue,
							refundBill.getSettlementAmountOfCoupon(),
							"验证SettlementAmountOfCoupon");
					Logger.verifyEquals(sellerId, refundBill.getSellerId(),
							"验证SellerId");
					Logger.verifyEquals(userId, refundBill.getBuyerId(),
							"验证BuyerId");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.comment("校验Ymt_RefundProduct表");
					Logger.verifyEquals(orderId, refundPro.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals("TH" + i + String.valueOf(orderId),
							refundPro.getRefundBillNo(), "验证RefundBillNo");
					if (settlementInvoiceList.get(i).get("BusinessNo")
							.equals(refundPro.getRefundBillNo())) {

						Logger.comment("校验Ymt_SettlementInvoice表");
						Logger.verifyEquals(
								"TH" + i + String.valueOf(orderId),
								(String) settlementInvoiceList.get(i).get(
										"BusinessNo"), "验证BusinessNo");
						Logger.verifyEquals(2, (Integer) settlementInvoiceList
								.get(i).get("BusinessType"), "验证BusinessType");
						Logger.verifyEquals(
								orderId,
								(Integer) settlementInvoiceList.get(i).get(
										"OrderId"), "验证OrderId");
						Logger.verifyEquals(
								((BigDecimal) settlementInvoiceList.get(i).get(
										"CashAmount"))
										.add((BigDecimal) settlementInvoiceList
												.get(i).get("CouponAmount")),
								(BigDecimal) settlementInvoiceList.get(i).get(
										"TotalAmount"), "验证TotalAmount");
						Logger.verifyEquals(
								refundBill.getRefundAmount(),
								(BigDecimal) settlementInvoiceList.get(i).get(
										"CashAmount"), "验证CashAmount");
						// 退的ymt 平台优惠券
						Logger.verifyEquals(
								productYmtCouponValue,
								(BigDecimal) settlementInvoiceList.get(i).get(
										"CouponAmount"), "验证CouponAmount");
						Logger.verifyEquals(
								sellerId,
								(Integer) settlementInvoiceList.get(i).get(
										"SellerId"), "验证SellerId");
						Logger.verifyEquals(
								"退款结算",
								(String) settlementInvoiceList.get(i).get(
										"Remark"), "验证Remark");
						Logger.verifyEquals(1, (Integer) settlementInvoiceList
								.get(i).get("SettlementStatus"),
								"验证SettlementStatus");
						Logger.verifyEquals(1, (Integer) settlementInvoiceList
								.get(i).get("SettlementUser"),
								"验证SettlementUser");
						Logger.verifyEquals(
								null,
								(String) settlementInvoiceList.get(i).get(
										"ProcessResult"), "验证ProcessResult");
						Logger.comment("校验ymt_orderinfo表");
						Logger.verifyEquals(10, (Integer) orderInfoList.get(i)
								.get("iProductRefundStatus"),
								"验证iProductRefundStatus");
						// 资金流水表
						List<YmtAccountEntry> ymtActList = new AccountDefaultWapper()
								.selectAccountEntryByOriginalNo((String) settlementInvoiceList
										.get(i).get("BusinessNo"));
						List<YmtAccountEntry> userActList = ymtActList.stream()
								.filter(act -> act.getUserid() == userId)
								.collect(Collectors.toList());
						Logger.verifyEquals(((BigDecimal) settlementInvoiceList
								.get(i).get("fAccountAmount"))
								.compareTo(BigDecimal.ZERO) > 0 ? 1 : 0,
								userActList.size(), "验证用户账户流水表记录");
						if (userActList.size() > 0) {
							Logger.comment("校验Ymt_AccountEntry表");
							Logger.verifyEquals(
									(BigDecimal) settlementInvoiceList.get(i)
											.get("fAccountAmount"), userActList
											.get(0).getAmount(),
									"验证用户账户流水表Amount");
						}
						List<YmtAccountEntry> sellerActList = ymtActList
								.stream()
								.filter(act -> act.getUserid() == sellerId)
								.collect(Collectors.toList());
						Logger.verifyEquals(0, sellerActList.size(),
								"验证用户账户流水表记录");
					}
				}
				Logger.comment("校验ymt_orders表");
				Logger.verifyEquals(12,
						(Integer) ymtOrders.get(0).get("iTradingStatus"),
						"验证iTradingStatus");
				Logger.verifyEquals(null,
						ymtOrders.get(0).get("iSalesRefundStatus"),
						"验证iSalesRefundStatus");
				Logger.comment("校验ymt_orderstate表");
				Logger.verifyEquals(
						settlementInvoiceList
								.stream()
								.map(account -> (BigDecimal) account
										.get("CashAmount"))
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountOfCash"),
						"验证fRefundedAmountOfCash");
				Logger.verifyEquals(null,
						ymtOrderState.get(0).get("fRefundedAmountToAccount"),
						"验证fRefundedAmountToAccount");
				Logger.verifyEquals(
						settlementInvoiceList
								.stream()
								.filter(account -> (Integer) account
										.get("BusinessType") == 2)
								.map(account -> (BigDecimal) account
										.get("CouponAmount"))
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountOfCoupon"),
						"验证fRefundedAmountOfCoupon");
				Logger.verifyEquals(
						settlementInvoiceList
								.stream()
								.filter(account -> (Integer) account
										.get("BusinessType") == 2)
								.map(account -> (BigDecimal) account
										.get("fThirdPartyAmount"))
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedPaidAmountToThirdParty"),
						"验证fRefundedPaidAmountToThirdParty");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SalesRefundSuccessRequest_005() {
		Logger.start(true, "余额+第三方支付宝组合支付。确认收货后,订单多个商品依次全部全款退款");
		try {
			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder4();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			OrderCallService orderCallService = new OrderCallService();

			// 用余额支付金额
			BigDecimal blanceAmout = new BigDecimal(47);
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "13";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payType);
			// 支付网关支付回调交易
			PaymentProxyCallService.notifyCall(payType,
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			// 等待支付网关异步处理
			Thread.sleep(5000);
			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 卖家发货
			orderCallService.dispatched(orderId, sellerId);
			// 用户确认收货
			orderCallService.confirmReceive(userId, orderId);

			Thread.sleep(2000);

			settlesellerIncome(orderId);
			// 申请退款
			applyRefundAllProduct(orderId);
			salesrefundsuccessrequestBean.setOperatorInfo("autotest");
			salesrefundsuccessrequestBean.setOrderId(orderId);
			salesrefundsuccessrequestBean.setRefundBillNo("TH0"
					+ String.valueOf(orderId));
			salesrefundsuccessrequestCall
					.setData(salesrefundsuccessrequestBean);
			Logger.comment("退该订单号" + orderId + "第一件商品");
			salesrefundsuccessrequestCall.callService();
			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");
			salesrefundsuccessrequestBean.setOrderId(orderId);
			salesrefundsuccessrequestBean.setRefundBillNo("TH1"
					+ String.valueOf(orderId));
			salesrefundsuccessrequestCall
					.setData(salesrefundsuccessrequestBean);
			Logger.comment("退该订单号" + orderId + "第二件商品");
			salesrefundsuccessrequestCall.callService();
			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");

			// 支付网关退款回调交易
			PaymentProxyCallService.refundNotifyCall(payType,
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			Thread.sleep(5000);
			DefaultWapper defaultWapper = new DefaultWapper();
			if (salesrefundsuccessrequestCall.getReturnData().equals("ok")) {
				// 数据库验
				// 查询交易退款结算表
				List<Map> settlementInvoiceList = defaultWapper
						.selectYmtSettlementInvoice(orderId);

				settlementInvoiceList = settlementInvoiceList.stream()
						.filter(s -> (Integer) s.get("BusinessType") == 2)
						.collect(Collectors.toList());

				// 订单商品表
				List<Map> orderInfoList = defaultWapper
						.selectOrderInfoByOderId(orderId);
				// 订单主表
				List<Map> ymtOrders = defaultWapper
						.selectOrderByOderId(orderId);
				// ymtOrderState 表
				List<Map> ymtOrderState = defaultWapper
						.selectOrderStateByOderId(orderId);
				YmtRefundWapper ymtRefund = new YmtRefundWapper();
				Map m = new HashMap();
				m.put("orderId", orderId);
				// m.put("refundBillNo", refundBillNo);
				for (int i = 0; i < orderInfoList.size(); i++) {
					// 订单退货记录
					YmtRefundBill refundBill = ymtRefund.selectRefundBill(m)
							.get(i);
					// 退货的商品记录
					YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(
							m).get(i);
					// 退款退货商品 catalogid
					String catalogId = refundPro.getCatalogId();
					// 商品使用的平台优惠券
					BigDecimal productYmtCouponValue = BigDecimal.ZERO;
					for (Map m1 : orderInfoList) {
						if (((String) m1.get("sCatalogId")).equals(catalogId)) {
							productYmtCouponValue = (BigDecimal) m1
									.get("fYmtCouponAmount");
						}
					}
					Logger.comment("校验订单号" + orderId + "第" + (i + 1) + "件商品");
					Logger.comment("校验Ymt_RefundBill表");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals("TH" + i + String.valueOf(orderId),
							refundBill.getRefundBillNo(), "验证RefundBillNo");
					Logger.verifyEquals(1, refundBill.getRefundStatus(),
							"验证RefundStatus");
					Logger.verifyEquals(1, refundBill.getSettlementStatus(),
							"验证SettlementStatus");
					Logger.verifyEquals(10, refundBill.getSalesRefundStatus(),
							"验证SalesRefundStatus");
					Logger.verifyEquals(1, refundBill.getRefundType(),
							"验证RefundType");
					Logger.verifyEquals("autotest refund",
							refundBill.getReason(), "验证Reason");
					// 退的平台优惠券
					Logger.verifyEquals(productYmtCouponValue,
							refundBill.getSettlementAmountOfCoupon(),
							"验证SettlementAmountOfCoupon");
					Logger.verifyEquals(sellerId, refundBill.getSellerId(),
							"验证SellerId");
					Logger.verifyEquals(userId, refundBill.getBuyerId(),
							"验证BuyerId");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.comment("校验Ymt_RefundProduct表");
					Logger.verifyEquals(orderId, refundPro.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals("TH" + i + String.valueOf(orderId),
							refundPro.getRefundBillNo(), "验证RefundBillNo");
					if (settlementInvoiceList.get(i).get("BusinessNo")
							.equals(refundPro.getRefundBillNo())) {
						Logger.comment("校验Ymt_SettlementInvoice表");
						Logger.verifyEquals(
								"TH" + i + String.valueOf(orderId),
								(String) settlementInvoiceList.get(i).get(
										"BusinessNo"), "验证BusinessNo");
						Logger.verifyEquals(2, (Integer) settlementInvoiceList
								.get(i).get("BusinessType"), "验证BusinessType");
						Logger.verifyEquals(
								orderId,
								(Integer) settlementInvoiceList.get(i).get(
										"OrderId"), "验证OrderId");
						Logger.verifyEquals(
								((BigDecimal) settlementInvoiceList.get(i).get(
										"CashAmount"))
										.add((BigDecimal) settlementInvoiceList
												.get(i).get("CouponAmount")),
								(BigDecimal) settlementInvoiceList.get(i).get(
										"TotalAmount"), "验证TotalAmount");
						Logger.verifyEquals(
								refundBill.getRefundAmount(),
								(BigDecimal) settlementInvoiceList.get(i).get(
										"CashAmount"), "验证CashAmount");
						// 退的ymt 平台优惠券
						Logger.verifyEquals(
								productYmtCouponValue,
								(BigDecimal) settlementInvoiceList.get(i).get(
										"CouponAmount"), "验证CouponAmount");
						Logger.verifyEquals(
								sellerId,
								(Integer) settlementInvoiceList.get(i).get(
										"SellerId"), "验证SellerId");
						Logger.verifyEquals(
								"退款结算",
								(String) settlementInvoiceList.get(i).get(
										"Remark"), "验证Remark");
						Logger.verifyEquals(1, (Integer) settlementInvoiceList
								.get(i).get("SettlementStatus"),
								"验证SettlementStatus");
						Logger.verifyEquals(2, (Integer) settlementInvoiceList
								.get(i).get("SettlementUser"),
								"验证SettlementUser");
						Logger.verifyEquals(
								null,
								(String) settlementInvoiceList.get(i).get(
										"ProcessResult"), "验证ProcessResult");
						// 资金流水表
						List<YmtAccountEntry> ymtActList = new AccountDefaultWapper()
								.selectAccountEntryByOriginalNo((String) settlementInvoiceList
										.get(i).get("BusinessNo"));
						List<YmtAccountEntry> userActList = ymtActList.stream()
								.filter(act -> act.getUserid() == userId)
								.collect(Collectors.toList());
						Logger.verifyEquals(((BigDecimal) settlementInvoiceList
								.get(i).get("fAccountAmount"))
								.compareTo(BigDecimal.ZERO) > 0 ? 1 : 0,
								userActList.size(), "验证用户账户流水表记录");

						if (userActList.size() > 0) {
							Logger.comment("校验Ymt_AccountEntry表");
							Logger.verifyEquals(
									(BigDecimal) settlementInvoiceList.get(i)
											.get("fAccountAmount"), userActList
											.get(0).getAmount(),
									"验证用户账户流水表Amount");
						}
						List<YmtAccountEntry> sellerActList = ymtActList
								.stream()
								.filter(act -> act.getUserid() == sellerId)
								.collect(Collectors.toList());
						Logger.verifyEquals(1, sellerActList.size(),
								"验证商家账户流水表记录");

						if (sellerActList.size() > 0) {
							Logger.comment("校验Ymt_AccountEntry表");
							Logger.verifyEquals(
									(BigDecimal) settlementInvoiceList.get(i)
											.get("TotalAmount"),
									sellerActList.get(0).getAmount()
											.multiply(new BigDecimal(-1)),
									"验证商家账户流水表Amount");
						}
					}
					Logger.comment("校验ymt_orderinfo表");
					Logger.verifyEquals(
							10,
							(Integer) orderInfoList.get(i).get(
									"iProductRefundStatus"),
							"验证iProductRefundStatus");

				}
				Logger.comment("校验ymt_orderstate表");
				Logger.verifyEquals(
						settlementInvoiceList
								.stream()
								.filter(account -> (Integer) account
										.get("BusinessType") == 2)
								.map(account -> (BigDecimal) account
										.get("CashAmount"))
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountOfCash"),
						"验证fRefundedAmountOfCash");
				Logger.verifyEquals(
						settlementInvoiceList
								.stream()
								.filter(account -> (Integer) account
										.get("BusinessType") == 2)
								.map(account -> (BigDecimal) account
										.get("fAccountAmount"))
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountToAccount"),
						"验证fRefundedAmountToAccount");
				Logger.verifyEquals(
						settlementInvoiceList
								.stream()
								.filter(account -> (Integer) account
										.get("BusinessType") == 2)
								.map(account -> (BigDecimal) account
										.get("CouponAmount"))
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountOfCoupon"),
						"验证fRefundedAmountOfCoupon");
				Logger.verifyEquals(
						settlementInvoiceList
								.stream()
								.filter(account -> (Integer) account
										.get("BusinessType") == 2)
								.map(account -> (BigDecimal) account
										.get("fThirdPartyAmount"))
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedPaidAmountToThirdParty"),
						"验证fRefundedPaidAmountToThirdParty");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SalesRefundSuccessRequest_006() {
		Logger.start(true, "全部第三方支付宝支付。确认收货后,订单多个商品依次全部全款退款");
		try {
			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder4();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			OrderCallService orderCallService = new OrderCallService();
			// 用余额支付金额
			BigDecimal blanceAmout = BigDecimal.ZERO;
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "13";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payType);
			// 支付网关支付回调交易
			PaymentProxyCallService.notifyCall(payType,
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			// 等待支付网关异步处理
			Thread.sleep(5000);
			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 卖家发货
			orderCallService.dispatched(orderId, sellerId);
			// 用户确认收货
			orderCallService.confirmReceive(userId, orderId);
			Thread.sleep(3000);
			// 对结算单进行结算
			settlesellerIncome(orderId);
			// 申请退款
			applyRefundAllProduct(orderId);
			salesrefundsuccessrequestBean.setOperatorInfo("autotest");
			salesrefundsuccessrequestBean.setOrderId(orderId);
			salesrefundsuccessrequestBean.setRefundBillNo("TH0"
					+ String.valueOf(orderId));
			salesrefundsuccessrequestCall
					.setData(salesrefundsuccessrequestBean);
			Logger.comment("退该订单号" + orderId + "第一件商品");
			salesrefundsuccessrequestCall.callService();
			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");
			salesrefundsuccessrequestBean.setOrderId(orderId);
			salesrefundsuccessrequestBean.setRefundBillNo("TH1"
					+ String.valueOf(orderId));
			salesrefundsuccessrequestCall
					.setData(salesrefundsuccessrequestBean);
			Logger.comment("退该订单号" + orderId + "第二件商品");
			salesrefundsuccessrequestCall.callService();
			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");

			// 支付网关退款回调交易
			PaymentProxyCallService.refundNotifyCall(payType,
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			Thread.sleep(5000);
			DefaultWapper defaultWapper = new DefaultWapper();
			if (salesrefundsuccessrequestCall.getReturnData().equals("ok")) {
				// 数据库验
				// 查询交易退款结算表
				List<Map> settlementInvoiceList = defaultWapper
						.selectYmtSettlementInvoice(orderId);
				// 订单商品表
				List<Map> orderInfoList = defaultWapper
						.selectOrderInfoByOderId(orderId);
				// 订单主表
				List<Map> ymtOrders = defaultWapper
						.selectOrderByOderId(orderId);
				// ymtOrderState 表
				List<Map> ymtOrderState = defaultWapper
						.selectOrderStateByOderId(orderId);
				YmtRefundWapper ymtRefund = new YmtRefundWapper();
				Map m = new HashMap();
				m.put("orderId", orderId);
				for (int i = 0; i < orderInfoList.size(); i++) {
					// 订单退货记录
					YmtRefundBill refundBill = ymtRefund.selectRefundBill(m)
							.get(i);
					// 退货的商品记录
					YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(
							m).get(i);
					// 退款退货商品 catalogid
					String catalogId = refundPro.getCatalogId();
					// 商品使用的平台优惠券
					BigDecimal productYmtCouponValue = BigDecimal.ZERO;
					for (Map m1 : orderInfoList) {
						if (((String) m1.get("sCatalogId")).equals(catalogId)) {
							productYmtCouponValue = (BigDecimal) m1
									.get("fYmtCouponAmount");
						}
					}
					Logger.comment("校验订单号" + orderId + "第" + (i + 1) + "件商品");
					Logger.comment("校验Ymt_RefundBill表");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals("TH" + i + String.valueOf(orderId),
							refundBill.getRefundBillNo(), "验证RefundBillNo");
					Logger.verifyEquals(1, refundBill.getRefundStatus(),
							"验证RefundStatus");
					Logger.verifyEquals(1, refundBill.getSettlementStatus(),
							"验证SettlementStatus");
					Logger.verifyEquals(10, refundBill.getSalesRefundStatus(),
							"验证SalesRefundStatus");
					Logger.verifyEquals(1, refundBill.getRefundType(),
							"验证RefundType");
					Logger.verifyEquals("autotest refund",
							refundBill.getReason(), "验证Reason");
					// 退的平台优惠券
					Logger.verifyEquals(productYmtCouponValue,
							refundBill.getSettlementAmountOfCoupon(),
							"验证SettlementAmountOfCoupon");
					Logger.verifyEquals(sellerId, refundBill.getSellerId(),
							"验证SellerId");
					Logger.verifyEquals(userId, refundBill.getBuyerId(),
							"验证BuyerId");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.comment("校验Ymt_RefundProduct表");
					Logger.verifyEquals(orderId, refundPro.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals("TH" + i + String.valueOf(orderId),
							refundPro.getRefundBillNo(), "验证RefundBillNo");
					if (settlementInvoiceList.get(i).get("BusinessNo")
							.equals(refundPro.getRefundBillNo())) {
						Logger.comment("校验Ymt_SettlementInvoice表");
						Logger.verifyEquals(
								"TH" + i + String.valueOf(orderId),
								(String) settlementInvoiceList.get(i).get(
										"BusinessNo"), "验证BusinessNo");
						Logger.verifyEquals(2, (Integer) settlementInvoiceList
								.get(i).get("BusinessType"), "验证BusinessType");
						Logger.verifyEquals(
								orderId,
								(Integer) settlementInvoiceList.get(i).get(
										"OrderId"), "验证OrderId");
						Logger.verifyEquals(
								((BigDecimal) settlementInvoiceList.get(i).get(
										"CashAmount"))
										.add((BigDecimal) settlementInvoiceList
												.get(i).get("CouponAmount")),
								(BigDecimal) settlementInvoiceList.get(i).get(
										"TotalAmount"), "验证TotalAmount");
						Logger.verifyEquals(
								refundBill.getRefundAmount(),
								(BigDecimal) settlementInvoiceList.get(i).get(
										"CashAmount"), "验证CashAmount");
						// 退的ymt 平台优惠券
						Logger.verifyEquals(
								productYmtCouponValue,
								(BigDecimal) settlementInvoiceList.get(i).get(
										"CouponAmount"), "验证CouponAmount");
						Logger.verifyEquals(
								sellerId,
								(Integer) settlementInvoiceList.get(i).get(
										"SellerId"), "验证SellerId");
						Logger.verifyEquals(
								"退款结算",
								(String) settlementInvoiceList.get(i).get(
										"Remark"), "验证Remark");
						Logger.verifyEquals(1, (Integer) settlementInvoiceList
								.get(i).get("SettlementStatus"),
								"验证SettlementStatus");
						Logger.verifyEquals(2, (Integer) settlementInvoiceList
								.get(i).get("SettlementUser"),
								"验证SettlementUser");
						Logger.verifyEquals(
								null,
								(String) settlementInvoiceList.get(i).get(
										"ProcessResult"), "验证ProcessResult");
						// 资金流水表
						List<YmtAccountEntry> ymtActList = new AccountDefaultWapper()
								.selectAccountEntryByOriginalNo((String) settlementInvoiceList
										.get(i).get("BusinessNo"));
						List<YmtAccountEntry> userActList = ymtActList.stream()
								.filter(act -> act.getUserid() == userId)
								.collect(Collectors.toList());
						Logger.verifyEquals(((BigDecimal) settlementInvoiceList
								.get(i).get("fAccountAmount"))
								.compareTo(BigDecimal.ZERO) > 0 ? 1 : 0,
								userActList.size(), "验证用户账户流水表记录");
						if (userActList.size() > 0) {
							Logger.comment("校验Ymt_AccountEntry表");
							Logger.verifyEquals(
									(BigDecimal) settlementInvoiceList.get(i)
											.get("fAccountAmount"), userActList
											.get(0).getAmount(),
									"验证用户账户流水表Amount");
						}
						List<YmtAccountEntry> sellerActList = ymtActList
								.stream()
								.filter(act -> act.getUserid() == sellerId)
								.collect(Collectors.toList());
						Logger.verifyEquals(1, sellerActList.size(),
								"验证商家账户流水表记录");
						if (sellerActList.size() > 0) {
							Logger.comment("校验Ymt_AccountEntry表");
							Logger.verifyEquals(
									(BigDecimal) settlementInvoiceList.get(i)
											.get("TotalAmount"),
									sellerActList.get(0).getAmount()
											.multiply(new BigDecimal(-1)),
									"验证商家账户流水表Amount");
						}
					}
					Logger.comment("校验ymt_orderinfo表");
					Logger.verifyEquals(
							10,
							(Integer) orderInfoList.get(i).get(
									"iProductRefundStatus"),
							"验证iProductRefundStatus");

				}
				Logger.comment("校验ymt_orderstate表");
				Logger.verifyEquals(
						settlementInvoiceList
								.stream()
								.filter(account -> (Integer) account
										.get("BusinessType") == 2)
								.map(account -> (BigDecimal) account
										.get("CashAmount"))
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountOfCash"),
						"验证fRefundedAmountOfCash");
				Logger.verifyEquals(
						settlementInvoiceList
								.stream()
								.filter(account -> (Integer) account
										.get("BusinessType") == 2)
								.map(account -> (BigDecimal) account
										.get("fAccountAmount"))
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountToAccount"),
						"验证fRefundedAmountToAccount");
				Logger.verifyEquals(
						settlementInvoiceList
								.stream()
								.filter(account -> (Integer) account
										.get("BusinessType") == 2)
								.map(account -> (BigDecimal) account
										.get("CouponAmount"))
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountOfCoupon"),
						"验证fRefundedAmountOfCoupon");
				Logger.verifyEquals(
						settlementInvoiceList
								.stream()
								.filter(account -> (Integer) account
										.get("BusinessType") == 2)
								.map(account -> (BigDecimal) account
										.get("fThirdPartyAmount"))
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedPaidAmountToThirdParty"),
						"验证fRefundedPaidAmountToThirdParty");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SalesRefundSuccessRequest_007() {
		Logger.start(true, "全部第三方微信支付。确认收货后,订单多个商品依次全部全款退款");
		try {

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder4();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			OrderCallService orderCallService = new OrderCallService();

			// 用余额支付金额
			BigDecimal blanceAmout = BigDecimal.ZERO;
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "15";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payType);
			// 支付网关支付回调交易
			PaymentProxyCallService.notifyCall(payType,
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			// 等待支付网关异步处理
			Thread.sleep(5000);
			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 卖家发货
			orderCallService.dispatched(orderId, sellerId);
			// 用户确认收货
			orderCallService.confirmReceive(userId, orderId);
			Thread.sleep(3000);
			// 对结算单进行结算
			settlesellerIncome(orderId);
			// 申请退款
			applyRefundAllProduct(orderId);

			salesrefundsuccessrequestBean.setOperatorInfo("autotest");
			salesrefundsuccessrequestBean.setOrderId(orderId);
			salesrefundsuccessrequestBean.setRefundBillNo("TH0"
					+ String.valueOf(orderId));
			salesrefundsuccessrequestCall
					.setData(salesrefundsuccessrequestBean);
			Logger.comment("退该订单号" + orderId + "第一件商品");
			salesrefundsuccessrequestCall.callService();
			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");
			salesrefundsuccessrequestBean.setOrderId(orderId);
			salesrefundsuccessrequestBean.setRefundBillNo("TH1"
					+ String.valueOf(orderId));
			salesrefundsuccessrequestCall
					.setData(salesrefundsuccessrequestBean);
			Logger.comment("退该订单号" + orderId + "第二件商品");
			salesrefundsuccessrequestCall.callService();
			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");

			// 支付网关退款回调交易
			PaymentProxyCallService.refundNotifyCall(payType,
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			Thread.sleep(5000);
			DefaultWapper defaultWapper = new DefaultWapper();
			if (salesrefundsuccessrequestCall.getReturnData().equals("ok")) {
				// 数据库验
				// 查询交易退款结算表
				List<Map> settlementInvoiceList = defaultWapper
						.selectYmtSettlementInvoice(orderId);

				settlementInvoiceList = settlementInvoiceList.stream()
						.filter(s -> (Integer) s.get("BusinessType") == 2)
						.collect(Collectors.toList());
				// 订单商品表
				List<Map> orderInfoList = defaultWapper
						.selectOrderInfoByOderId(orderId);
				// 订单主表
				List<Map> ymtOrders = defaultWapper
						.selectOrderByOderId(orderId);
				// ymtOrderState 表
				List<Map> ymtOrderState = defaultWapper
						.selectOrderStateByOderId(orderId);
				YmtRefundWapper ymtRefund = new YmtRefundWapper();
				Map m = new HashMap();
				m.put("orderId", orderId);
				// m.put("refundBillNo", refundBillNo);
				for (int i = 0; i < orderInfoList.size(); i++) {
					// 订单退货记录
					YmtRefundBill refundBill = ymtRefund.selectRefundBill(m)
							.get(i);
					// 退货的商品记录
					YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(
							m).get(i);
					// 退款退货商品 catalogid
					String catalogId = refundPro.getCatalogId();
					// 商品使用的平台优惠券
					BigDecimal productYmtCouponValue = BigDecimal.ZERO;
					for (Map m1 : orderInfoList) {
						if (((String) m1.get("sCatalogId")).equals(catalogId)) {
							productYmtCouponValue = (BigDecimal) m1
									.get("fYmtCouponAmount");
						}
					}
					Logger.comment("校验订单号" + orderId + "第" + (i + 1) + "件商品");
					Logger.comment("校验Ymt_RefundBill表");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals("TH" + i + String.valueOf(orderId),
							refundBill.getRefundBillNo(), "验证RefundBillNo");
					Logger.verifyEquals(1, refundBill.getRefundStatus(),
							"验证RefundStatus");
					Logger.verifyEquals(1, refundBill.getSettlementStatus(),
							"验证SettlementStatus");
					Logger.verifyEquals(10, refundBill.getSalesRefundStatus(),
							"验证SalesRefundStatus");
					Logger.verifyEquals(1, refundBill.getRefundType(),
							"验证RefundType");
					Logger.verifyEquals("autotest refund",
							refundBill.getReason(), "验证Reason");
					// 退的平台优惠券
					Logger.verifyEquals(productYmtCouponValue,
							refundBill.getSettlementAmountOfCoupon(),
							"验证SettlementAmountOfCoupon");
					Logger.verifyEquals(sellerId, refundBill.getSellerId(),
							"验证SellerId");
					Logger.verifyEquals(userId, refundBill.getBuyerId(),
							"验证BuyerId");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.comment("校验Ymt_RefundProduct表");
					Logger.verifyEquals(orderId, refundPro.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals("TH" + i + String.valueOf(orderId),
							refundPro.getRefundBillNo(), "验证RefundBillNo");
					Logger.comment("校验Ymt_SettlementInvoice表");
					if (settlementInvoiceList.get(i).get("BusinessNo")
							.equals(refundPro.getRefundBillNo())) {
						Logger.verifyEquals(
								"TH" + i + String.valueOf(orderId),
								(String) settlementInvoiceList.get(i).get(
										"BusinessNo"), "验证BusinessNo");
						Logger.verifyEquals(2, (Integer) settlementInvoiceList
								.get(i).get("BusinessType"), "验证BusinessType");
						Logger.verifyEquals(
								orderId,
								(Integer) settlementInvoiceList.get(i).get(
										"OrderId"), "验证OrderId");
						Logger.verifyEquals(
								((BigDecimal) settlementInvoiceList.get(i).get(
										"CashAmount"))
										.add((BigDecimal) settlementInvoiceList
												.get(i).get("CouponAmount")),
								(BigDecimal) settlementInvoiceList.get(i).get(
										"TotalAmount"), "验证TotalAmount");
						Logger.verifyEquals(
								refundBill.getRefundAmount(),
								(BigDecimal) settlementInvoiceList.get(i).get(
										"CashAmount"), "验证CashAmount");
						// 退的ymt 平台优惠券
						Logger.verifyEquals(
								productYmtCouponValue,
								(BigDecimal) settlementInvoiceList.get(i).get(
										"CouponAmount"), "验证CouponAmount");
						Logger.verifyEquals(
								sellerId,
								(Integer) settlementInvoiceList.get(i).get(
										"SellerId"), "验证SellerId");
						Logger.verifyEquals(
								"退款结算",
								(String) settlementInvoiceList.get(i).get(
										"Remark"), "验证Remark");
						Logger.verifyEquals(1, (Integer) settlementInvoiceList
								.get(i).get("SettlementStatus"),
								"验证SettlementStatus");
						Logger.verifyEquals(2, (Integer) settlementInvoiceList
								.get(i).get("SettlementUser"),
								"验证SettlementUser");
						Logger.verifyEquals(
								null,
								(String) settlementInvoiceList.get(i).get(
										"ProcessResult"), "验证ProcessResult");
						// 资金流水表
						List<YmtAccountEntry> ymtActList = new AccountDefaultWapper()
								.selectAccountEntryByOriginalNo((String) settlementInvoiceList
										.get(i).get("BusinessNo"));
						List<YmtAccountEntry> userActList = ymtActList.stream()
								.filter(act -> act.getUserid() == userId)
								.collect(Collectors.toList());
						Logger.verifyEquals(((BigDecimal) settlementInvoiceList
								.get(i).get("fAccountAmount"))
								.compareTo(BigDecimal.ZERO) > 0 ? 1 : 0,
								userActList.size(), "验证用户账户流水表记录");
						if (userActList.size() > 0) {
							Logger.comment("校验Ymt_AccountEntry表");
							Logger.verifyEquals(
									(BigDecimal) settlementInvoiceList.get(i)
											.get("fAccountAmount"), userActList
											.get(0).getAmount(),
									"验证用户账户流水表Amount");
						}
						List<YmtAccountEntry> sellerActList = ymtActList
								.stream()
								.filter(act -> act.getUserid() == sellerId)
								.collect(Collectors.toList());
						Logger.verifyEquals(1, sellerActList.size(),
								"验证商家账户流水表记录");
						if (sellerActList.size() > 0) {
							Logger.comment("校验Ymt_AccountEntry表");
							Logger.verifyEquals(
									(BigDecimal) settlementInvoiceList.get(i)
											.get("TotalAmount"),
									sellerActList.get(0).getAmount()
											.multiply(new BigDecimal(-1)),
									"验证商家账户流水表Amount");
						}
					}
					Logger.comment("校验ymt_orderinfo表");
					Logger.verifyEquals(
							10,
							(Integer) orderInfoList.get(i).get(
									"iProductRefundStatus"),
							"验证iProductRefundStatus");

				}
				Logger.comment("校验ymt_orderstate表");
				Logger.verifyEquals(
						settlementInvoiceList
								.stream()
								.filter(account -> (Integer) account
										.get("BusinessType") == 2)
								.map(account -> (BigDecimal) account
										.get("CashAmount"))
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountOfCash"),
						"验证fRefundedAmountOfCash");
				Logger.verifyEquals(
						settlementInvoiceList
								.stream()
								.filter(account -> (Integer) account
										.get("BusinessType") == 2)
								.map(account -> (BigDecimal) account
										.get("fAccountAmount"))
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountToAccount"),
						"验证fRefundedAmountToAccount");

				Logger.verifyEquals(
						settlementInvoiceList
								.stream()
								.filter(account -> (Integer) account
										.get("BusinessType") == 2)
								.map(account -> (BigDecimal) account
										.get("fThirdPartyAmount"))
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedPaidAmountToThirdParty"),
						"验证fRefundedPaidAmountToThirdParty");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SalesRefundSuccessRequest_008() {
		Logger.start(true, "组合支付,订单部分退款,然后确认收货");
		try {

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder4();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			OrderCallService orderCallService = new OrderCallService();
			// 用余额支付金额
			BigDecimal blanceAmout = new BigDecimal(32);
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "13";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payType);
			// 支付网关支付回调交易
			PaymentProxyCallService.notifyCall(payType,
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			// 等待支付网关异步处理
			Thread.sleep(5000);
			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 发货
			orderCallService.dispatched(orderId, sellerId);

			BigDecimal applyRefundAmout = blanceAmout.add(BigDecimal.ONE);

			// 申请退款
			ApplySalesRefundRequestBean applysalesrefundrequestBean = orderCallService
					.applySalesRefundRequestInJavaBean(orderId);

			String refundBillNo = "TH0" + String.valueOf(orderId);
			applysalesrefundrequestBean.getSalesRefundInfoList().remove(1);
			applysalesrefundrequestBean.getSalesRefundInfoList().get(0)
					.setRefundAmount(applyRefundAmout);

			ApplySalesRefundRequestCall applysalesrefundrequestCall = new ApplySalesRefundRequestCall();
			applysalesrefundrequestCall.setData(false,
					applysalesrefundrequestBean);
			applysalesrefundrequestCall.callService();

			salesrefundsuccessrequestBean.setOperatorInfo("autotest");
			salesrefundsuccessrequestBean.setOrderId(orderId);
			salesrefundsuccessrequestBean.setRefundBillNo(refundBillNo);
			salesrefundsuccessrequestCall
					.setData(salesrefundsuccessrequestBean);
			salesrefundsuccessrequestCall.callService();
			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");

			// 支付网关退款回调交易
			PaymentProxyCallService.refundNotifyCall(payType,
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			Thread.sleep(5000);
			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");
			// 确认收货
			orderCallService.confirmReceive(userId, orderId);

			Thread.sleep(3000);
			// 对结算单进行结算

			settlesellerIncome(orderId);

			DefaultWapper defaultWapper = new DefaultWapper();

			if (salesrefundsuccessrequestCall.getReturnData().equals("ok")) {

				// 数据库验
				// 查询交易退款结算表
				List<Map> settlementInvoiceList = defaultWapper
						.selectYmtSettlementInvoice(orderId);

				settlementInvoiceList = settlementInvoiceList.stream()
						.filter(s -> (Integer) s.get("BusinessType") == 2)
						.collect(Collectors.toList());
				// 订单商品表
				List<Map> orderInfoList = defaultWapper
						.selectOrderInfoByOderId(orderId);
				// 订单主表
				List<Map> ymtOrders = defaultWapper
						.selectOrderByOderId(orderId);
				// ymtOrderState 表
				List<Map> ymtOrderState = defaultWapper
						.selectOrderStateByOderId(orderId);

				/* 贝海发货，冻结，防止自动确认收货
				 * 				int isFrozen = new DefaultWapper().getFrozenStatus(orderId);

								Logger.verifyEquals(0, isFrozen, "验证Ymt_Order_Frozen.bFrozen");;*/

				YmtRefundWapper ymtRefund = new YmtRefundWapper();

				Map m = new HashMap();
				m.put("orderId", orderId);
				m.put("refundBillNo", refundBillNo);

				// 订单退货记录
				YmtRefundBill refundBill = ymtRefund.selectRefundBill(m).get(0);
				// 退货的商品记录
				YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(m)
						.get(0);

				// 退款退货商品 catalogid
				String catalogId = refundPro.getCatalogId();
				// 商品使用的平台优惠券
				BigDecimal productYmtCouponValue = BigDecimal.ZERO;
				for (Map m1 : orderInfoList) {

					if (((String) m1.get("sCatalogId")).equals(catalogId)) {
						BigDecimal refoundAmout = ((BigDecimal) m1
								.get("fProductPrice"))
								.multiply(
										new BigDecimal((Integer) m1
												.get("iAmount")))
								.subtract(
										((BigDecimal) m1
												.get("fSellerCouponAmount")))
								.subtract(
										((BigDecimal) m1
												.get("fYmtCouponAmount")))
								.add(DataUtil.BigDecimall
										.GetValueOrDefault((BigDecimal) m1
												.get("fFreight")));

						productYmtCouponValue = applyRefundAmout.multiply(
								(BigDecimal) m1.get("fYmtCouponAmount"))
								.divide(refoundAmout, 2, BigDecimal.ROUND_DOWN);
					}
				}
				Logger.comment("校验订单号" + orderId + "第" + 1 + "件商品");
				Logger.comment("校验Ymt_RefundBill表");
				Logger.verifyEquals(orderId, refundBill.getOrderId(),
						"验证OrderId");
				Logger.verifyEquals(refundBillNo, refundBill.getRefundBillNo(),
						"验证RefundBillNo");
				Logger.verifyEquals(1, refundBill.getRefundStatus(),
						"验证RefundStatus");
				Logger.verifyEquals(1, refundBill.getSettlementStatus(),
						"验证SettlementStatus");
				Logger.verifyEquals(10, refundBill.getSalesRefundStatus(),
						"验证SalesRefundStatus");
				Logger.verifyEquals(1, refundBill.getRefundType(),
						"验证RefundType");
				Logger.verifyEquals("autotest refund", refundBill.getReason(),
						"验证Reason");
				// 退的平台优惠券
				Logger.verifyEquals(productYmtCouponValue,
						refundBill.getSettlementAmountOfCoupon(),
						"验证SettlementAmountOfCoupon");
				Logger.verifyEquals(sellerId, refundBill.getSellerId(),
						"验证SellerId");
				Logger.verifyEquals(userId, refundBill.getBuyerId(),
						"验证BuyerId");
				Logger.verifyEquals(orderId, refundBill.getOrderId(),
						"验证OrderId");
				Logger.comment("校验Ymt_RefundProduct表");
				Logger.verifyEquals(orderId, refundPro.getOrderId(),
						"验证OrderId");
				Logger.verifyEquals(refundBillNo, refundPro.getRefundBillNo(),
						"验证RefundBillNo");
				Logger.comment("校验Ymt_SettlementInvoice表");
				for (int i = 0; i < settlementInvoiceList.size(); i++) {
					if (settlementInvoiceList.get(i).get("BusinessNo")
							.equals(refundPro.getRefundBillNo())) {
						Logger.verifyEquals(
								"TH" + 0 + String.valueOf(orderId),
								(String) settlementInvoiceList.get(i).get(
										"BusinessNo"), "验证BusinessNo");
						Logger.verifyEquals(2, (Integer) settlementInvoiceList
								.get(i).get("BusinessType"), "验证BusinessType");
						Logger.verifyEquals(
								orderId,
								(Integer) settlementInvoiceList.get(i).get(
										"OrderId"), "验证OrderId");
						Logger.verifyEquals(
								((BigDecimal) settlementInvoiceList.get(i).get(
										"CashAmount"))
										.add((BigDecimal) settlementInvoiceList
												.get(i).get("CouponAmount")),
								(BigDecimal) settlementInvoiceList.get(i).get(
										"TotalAmount"), "验证TotalAmount");
						Logger.verifyEquals(
								refundBill.getRefundAmount(),
								(BigDecimal) settlementInvoiceList.get(i).get(
										"CashAmount"), "验证CashAmount");
						// 退的ymt 平台优惠券
						Logger.verifyEquals(
								productYmtCouponValue,
								(BigDecimal) settlementInvoiceList.get(i).get(
										"CouponAmount"), "验证CouponAmount");
						Logger.verifyEquals(
								sellerId,
								(Integer) settlementInvoiceList.get(i).get(
										"SellerId"), "验证SellerId");
						Logger.verifyEquals(
								"退款结算",
								(String) settlementInvoiceList.get(i).get(
										"Remark"), "验证Remark");
						Logger.verifyEquals(1, (Integer) settlementInvoiceList
								.get(i).get("SettlementStatus"),
								"验证SettlementStatus");
						Logger.verifyEquals(1, (Integer) settlementInvoiceList
								.get(i).get("SettlementUser"),
								"验证SettlementUser");
						Logger.verifyEquals(
								null,
								(String) settlementInvoiceList.get(i).get(
										"ProcessResult"), "验证ProcessResult");
						// 资金流水表
						List<YmtAccountEntry> ymtActList = new AccountDefaultWapper()
								.selectAccountEntryByOriginalNo((String) settlementInvoiceList
										.get(i).get("BusinessNo"));
						List<YmtAccountEntry> userActList = ymtActList.stream()
								.filter(act -> act.getUserid() == userId)
								.collect(Collectors.toList());
						Logger.verifyEquals(((BigDecimal) settlementInvoiceList
								.get(i).get("fAccountAmount"))
								.compareTo(BigDecimal.ZERO) > 0 ? 1 : 0,
								userActList.size(), "验证用户账户流水表记录");
						if (userActList.size() > 0) {
							Logger.comment("校验Ymt_AccountEntry表");
							Logger.verifyEquals(
									(BigDecimal) settlementInvoiceList.get(i)
											.get("fAccountAmount"), userActList
											.get(0).getAmount(),
									"验证用户账户流水表Amount");
						}
					}
				}
				Logger.comment("校验ymt_orders表");
				Logger.verifyEquals(4,
						(Integer) ymtOrders.get(0).get("iTradingStatus"),
						"验证iTradingStatus");
				Logger.verifyEquals(null,
						ymtOrders.get(0).get("iSalesRefundStatus"),
						"验证iSalesRefundStatus");
				Logger.comment("校验ymt_orderstate表");
				Logger.verifyEquals(
						settlementInvoiceList
								.stream()
								.filter(account -> (Integer) account
										.get("BusinessType") == 2)
								.map(account -> (BigDecimal) account
										.get("CashAmount"))
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountOfCash"),
						"验证fRefundedAmountOfCash");
				Logger.verifyEquals(
						settlementInvoiceList
								.stream()
								.filter(account -> (Integer) account
										.get("BusinessType") == 2)
								.map(account -> (BigDecimal) account
										.get("CouponAmount"))
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountOfCoupon"),
						"验证fRefundedAmountOfCoupon");
				Logger.verifyEquals(
						settlementInvoiceList
								.stream()
								.filter(account -> (Integer) account
										.get("BusinessType") == 2)
								.map(account -> (BigDecimal) account
										.get("fAccountAmount"))
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						ymtOrderState.get(0).get("fRefundedAmountToAccount"),
						"验证fRefundedAmountToAccount");
				Logger.verifyEquals(
						settlementInvoiceList
								.stream()
								.filter(account -> (Integer) account
										.get("BusinessType") == 2)
								.map(account -> (BigDecimal) account
										.get("fThirdPartyAmount"))
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedPaidAmountToThirdParty"),
						"验证fRefundedPaidAmountToThirdParty");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SalesRefundSuccessRequest_009() {
		Logger.start(true, "确认收货后,商家备用金不够,退货退款结算失败");
		try {

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder4();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			OrderCallService orderCallService = new OrderCallService();
			// 用余额支付金额
			BigDecimal blanceAmout = BigDecimal.ZERO;
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "13";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payType);
			// 支付网关支付回调交易
			PaymentProxyCallService.notifyCall(payType,
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			// 等待支付网关异步处理
			Thread.sleep(5000);
			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 发货
			orderCallService.dispatched(orderId, sellerId);
			// 确认收货
			orderCallService.confirmReceive(userId, orderId);

			Thread.sleep(3000);
			// 对结算单进行结算
			settlesellerIncome(orderId);
			// 申请退款
			applyRefundAllProduct(orderId);
			String refundBillNo = "TH0" + String.valueOf(orderId);
			// 重置商家余额
			AccountCallServiceV2 AccountCallServiceV2 = new AccountCallServiceV2();
			String accountid = AccountCallServiceV2.getAccountId(sellerId);
			AccountCallServiceV2.resetAccount(accountid, new BigDecimal(10),
					BigDecimal.ZERO);

			salesrefundsuccessrequestBean.setOperatorInfo("autotest");
			salesrefundsuccessrequestBean.setOrderId(orderId);
			salesrefundsuccessrequestBean.setRefundBillNo(refundBillNo);
			salesrefundsuccessrequestCall
					.setData(salesrefundsuccessrequestBean);
			salesrefundsuccessrequestCall.callService();
			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");

			// 支付网关退款回调交易
			PaymentProxyCallService.refundNotifyCall(payType,
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			Thread.sleep(5000);

			DefaultWapper defaultWapper = new DefaultWapper();
			// 数据库验
			// 查询交易退款结算表
			List<Map> settlementInvoiceList = defaultWapper
					.selectYmtSettlementInvoice(orderId);
			// 订单商品表
			List<Map> orderInfoList = defaultWapper
					.selectOrderInfoByOderId(orderId);
			// 订单主表
			List<Map> ymtOrders = defaultWapper.selectOrderByOderId(orderId);
			// ymtOrderState 表
			List<Map> ymtOrderState = defaultWapper
					.selectOrderStateByOderId(orderId);
			YmtRefundWapper ymtRefund = new YmtRefundWapper();
			Map m = new HashMap();
			m.put("orderId", orderId);
			m.put("refundBillNo", refundBillNo);
			// 订单退货记录
			YmtRefundBill refundBill = ymtRefund.selectRefundBill(m).get(0);
			// 退货的商品记录
			YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(m)
					.get(0);
			// 退款退货商品 catalogid
			String catalogId = refundPro.getCatalogId();
			// 商品使用的平台优惠券
			BigDecimal productYmtCouponValue = BigDecimal.ZERO;
			for (Map m1 : orderInfoList) {
				if (((String) m1.get("sCatalogId")).equals(catalogId)) {
					productYmtCouponValue = (BigDecimal) m1
							.get("fYmtCouponAmount");
				}
			}
			Logger.comment("校验订单号" + orderId + "第1件商品");
			Logger.comment("校验Ymt_RefundBill表");
			Logger.verifyEquals(orderId, refundBill.getOrderId(), "验证OrderId");
			Logger.verifyEquals(refundBillNo, refundBill.getRefundBillNo(),
					"验证RefundBillNo");
			Logger.verifyEquals(0, refundBill.getRefundStatus(),
					"验证RefundStatus");
			Logger.verifyEquals(0, refundBill.getSettlementStatus(),
					"验证SettlementStatus");
			Logger.verifyEquals(10, refundBill.getSalesRefundStatus(),
					"验证SalesRefundStatus");
			Logger.verifyEquals(1, refundBill.getRefundType(), "验证RefundType");
			Logger.verifyEquals("autotest refund", refundBill.getReason(),
					"验证Reason");
			// 退的平台优惠券
			Logger.verifyEquals(productYmtCouponValue,
					refundBill.getSettlementAmountOfCoupon(),
					"验证SettlementAmountOfCoupon");
			Logger.verifyEquals(sellerId, refundBill.getSellerId(),
					"验证SellerId");
			Logger.verifyEquals(userId, refundBill.getBuyerId(), "验证BuyerId");
			Logger.verifyEquals(orderId, refundBill.getOrderId(), "验证OrderId");
			Logger.comment("校验Ymt_RefundProduct表");
			Logger.verifyEquals(orderId, refundPro.getOrderId(), "验证OrderId");
			Logger.verifyEquals(refundBillNo, refundPro.getRefundBillNo(),
					"验证RefundBillNo");
			List<Map> settlementInvoiceList2 = settlementInvoiceList
					.stream()
					.filter(settlement -> (Integer) settlement
							.get("BusinessType") == 2)
					.collect(Collectors.toList());
			Logger.comment("校验Ymt_SettlementInvoice表 退款结算");
			Logger.verifyEquals(refundBillNo, (String) settlementInvoiceList2
					.get(0).get("BusinessNo"), "验证BusinessNo");
			Logger.verifyEquals(
					2,
					(Integer) settlementInvoiceList2.get(0).get("BusinessType"),
					"验证BusinessType");
			Logger.verifyEquals(orderId, (Integer) settlementInvoiceList2
					.get(0).get("OrderId"), "验证OrderId");
			Logger.verifyEquals(
					((BigDecimal) settlementInvoiceList2.get(0).get(
							"CashAmount"))
							.add((BigDecimal) settlementInvoiceList2.get(0)
									.get("CouponAmount")),
					(BigDecimal) settlementInvoiceList2.get(0).get(
							"TotalAmount"), "验证TotalAmount");
			Logger.verifyEquals(refundBill.getRefundAmount(),
					(BigDecimal) settlementInvoiceList2.get(0)
							.get("CashAmount"), "验证CashAmount");
			// 确认收货的ymt 平台优惠券
			Logger.verifyEquals(
					refundBill.getSettlementAmountOfCoupon(),
					(BigDecimal) settlementInvoiceList2.get(0).get(
							"CouponAmount"), "验证CouponAmount");
			Logger.verifyEquals(sellerId,
					(Integer) settlementInvoiceList2.get(0).get("SellerId"),
					"验证SellerId");
			Logger.verifyEquals("退款结算", (String) settlementInvoiceList2.get(0)
					.get("Remark"), "验证Remark");
			Logger.verifyEquals(
					0,
					(Integer) settlementInvoiceList2.get(0).get(
							"SettlementStatus"), "验证SettlementStatus");
			Logger.verifyEquals(
					2,
					(Integer) settlementInvoiceList2.get(0).get(
							"SettlementUser"), "验证SettlementUser");
			Logger.verifyEquals(null, (String) settlementInvoiceList2.get(0)
					.get("ProcessResult"), "验证ProcessResult");
			Logger.comment("校验ymt_orderinfo表");
			Logger.verifyEquals(10,
					(Integer) orderInfoList.get(0).get("iProductRefundStatus"),
					"验证iProductRefundStatus");
			Logger.verifyEquals(1,
					(Integer) orderInfoList.get(1).get("iProductRefundStatus"),
					"验证iProductRefundStatus");
			Logger.comment("校验ymt_orders表");
			Logger.verifyEquals(4,
					(Integer) ymtOrders.get(0).get("iTradingStatus"),
					"验证iTradingStatus");
			Logger.verifyEquals(null, ymtOrders.get(0)
					.get("iSalesRefundStatus"), "验证iSalesRefundStatus");
			Logger.comment("校验ymt_orderstate表");
			Logger.verifyEquals(
					(BigDecimal) settlementInvoiceList2.get(0)
							.get("CashAmount"),
					(BigDecimal) ymtOrderState.get(0).get(
							"fRefundedAmountOfCash"), "验证fRefundedAmountOfCash");
			//			AccountCallServiceV2.resetAccount(accountid,
			//					new BigDecimal(99999999), BigDecimal.ZERO);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SalesRefundSuccessRequest_010() {
		Logger.start(true, "下单使用分别使用平台券优惠券，商家优惠券，多个商品依次全部退款，"
				+ "校验平台券金额按比例退，商家优惠券金额不退");
		try {

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder4();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal amount = placeOrderResp.getPayAmount();// 支付金额

			OrderCallService orderCallService = new OrderCallService();
			// 付款
			orderCallService.orderPayRequest(userId, amount, tradingId);
			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 申请退款
			applyRefundAllProduct(orderId);
			salesrefundsuccessrequestBean.setOperatorInfo("autotest");
			salesrefundsuccessrequestBean.setOrderId(orderId);
			salesrefundsuccessrequestBean.setRefundBillNo("TH0"
					+ String.valueOf(orderId));
			salesrefundsuccessrequestCall
					.setData(salesrefundsuccessrequestBean);
			Logger.comment("退该订单号" + orderId + "第一件商品");
			salesrefundsuccessrequestCall.callService();
			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");
			salesrefundsuccessrequestBean.setOrderId(orderId);
			salesrefundsuccessrequestBean.setRefundBillNo("TH1"
					+ String.valueOf(orderId));
			salesrefundsuccessrequestCall
					.setData(salesrefundsuccessrequestBean);
			Logger.comment("退该订单号" + orderId + "第二件商品");
			salesrefundsuccessrequestCall.callService();
			DefaultWapper defaultWapper = new DefaultWapper();
			if (salesrefundsuccessrequestCall.getReturnData().equals("ok")) {
				// 数据库验
				// 查询交易退款结算表
				List<Map> settlementInvoiceList = defaultWapper
						.selectYmtSettlementInvoice(orderId);
				// 订单商品表
				List<Map> orderInfoList = defaultWapper
						.selectOrderInfoByOderId(orderId);
				// 订单主表
				List<Map> ymtOrders = defaultWapper
						.selectOrderByOderId(orderId);
				// ymtOrderState 表
				List<Map> ymtOrderState = defaultWapper
						.selectOrderStateByOderId(orderId);
				YmtRefundWapper ymtRefund = new YmtRefundWapper();
				Map m = new HashMap();
				m.put("orderId", orderId);
				// m.put("refundBillNo", refundBillNo);
				for (int i = 0; i < orderInfoList.size(); i++) {
					// 订单退货记录
					YmtRefundBill refundBill = ymtRefund.selectRefundBill(m)
							.get(i);
					// 退货的商品记录
					YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(
							m).get(i);
					// 退款退货商品 catalogid
					String catalogId = refundPro.getCatalogId();
					// 商品使用的平台优惠券
					BigDecimal productYmtCouponValue = BigDecimal.ZERO;
					for (Map m1 : orderInfoList) {
						if (((String) m1.get("sCatalogId")).equals(catalogId)) {
							productYmtCouponValue = (BigDecimal) m1
									.get("fYmtCouponAmount");
						}
					}
					Logger.comment("校验订单号" + orderId + "第" + (i + 1) + "件商品");
					Logger.comment("校验Ymt_RefundBill表");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals("TH" + i + String.valueOf(orderId),
							refundBill.getRefundBillNo(), "验证RefundBillNo");
					Logger.verifyEquals(1, refundBill.getRefundStatus(),
							"验证RefundStatus");
					Logger.verifyEquals(1, refundBill.getSettlementStatus(),
							"验证SettlementStatus");
					Logger.verifyEquals(10, refundBill.getSalesRefundStatus(),
							"验证SalesRefundStatus");
					Logger.verifyEquals(1, refundBill.getRefundType(),
							"验证RefundType");
					Logger.verifyEquals("autotest refund",
							refundBill.getReason(), "验证Reason");
					// 退的平台优惠券
					Logger.verifyEquals(productYmtCouponValue,
							refundBill.getSettlementAmountOfCoupon(),
							"验证SettlementAmountOfCoupon");
					Logger.verifyEquals(sellerId, refundBill.getSellerId(),
							"验证SellerId");
					Logger.verifyEquals(userId, refundBill.getBuyerId(),
							"验证BuyerId");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.comment("校验Ymt_RefundProduct表");
					Logger.verifyEquals(orderId, refundPro.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals("TH" + i + String.valueOf(orderId),
							refundPro.getRefundBillNo(), "验证RefundBillNo");
					if (settlementInvoiceList.get(i).get("BusinessNo")
							.equals(refundPro.getRefundBillNo())) {

						Logger.comment("校验Ymt_SettlementInvoice表");
						Logger.verifyEquals(
								"TH" + i + String.valueOf(orderId),
								(String) settlementInvoiceList.get(i).get(
										"BusinessNo"), "验证BusinessNo");
						Logger.verifyEquals(2, (Integer) settlementInvoiceList
								.get(i).get("BusinessType"), "验证BusinessType");
						Logger.verifyEquals(
								orderId,
								(Integer) settlementInvoiceList.get(i).get(
										"OrderId"), "验证OrderId");
						Logger.verifyEquals(
								((BigDecimal) settlementInvoiceList.get(i).get(
										"CashAmount"))
										.add((BigDecimal) settlementInvoiceList
												.get(i).get("CouponAmount")),
								(BigDecimal) settlementInvoiceList.get(i).get(
										"TotalAmount"), "验证TotalAmount");
						Logger.verifyEquals(
								refundBill.getRefundAmount(),
								(BigDecimal) settlementInvoiceList.get(i).get(
										"CashAmount"), "验证CashAmount");
						// 退的ymt 平台优惠券
						Logger.verifyEquals(
								productYmtCouponValue,
								(BigDecimal) settlementInvoiceList.get(i).get(
										"CouponAmount"), "验证CouponAmount");
						Logger.verifyEquals(
								sellerId,
								(Integer) settlementInvoiceList.get(i).get(
										"SellerId"), "验证SellerId");
						Logger.verifyEquals(
								"退款结算",
								(String) settlementInvoiceList.get(i).get(
										"Remark"), "验证Remark");
						Logger.verifyEquals(1, (Integer) settlementInvoiceList
								.get(i).get("SettlementStatus"),
								"验证SettlementStatus");
						Logger.verifyEquals(1, (Integer) settlementInvoiceList
								.get(i).get("SettlementUser"),
								"验证SettlementUser");
						Logger.verifyEquals(
								null,
								(String) settlementInvoiceList.get(i).get(
										"ProcessResult"), "验证ProcessResult");
						Logger.verifyEquals(
								refundBill.getRefundAmount(),
								(BigDecimal) settlementInvoiceList.get(i).get(
										"fAccountAmount"), "验证fAccountAmount");
						Logger.verifyEquals(
								BigDecimal.ZERO.setScale(2),
								(BigDecimal) settlementInvoiceList.get(i).get(
										"fThirdPartyAmount"),
								"验证fThirdPartyAmount");
						Logger.comment("校验ymt_orderinfo表");
						Logger.verifyEquals(10, (Integer) orderInfoList.get(i)
								.get("iProductRefundStatus"),
								"验证iProductRefundStatus");
						// 资金流水表
						List<YmtAccountEntry> ymtActList = new AccountDefaultWapper()
								.selectAccountEntryByOriginalNo((String) settlementInvoiceList
										.get(i).get("BusinessNo"));
						Logger.comment("校验Ymt_AccountEntry表");
						Logger.verifyEquals((BigDecimal) settlementInvoiceList
								.get(i).get("CashAmount"), ymtActList.get(0)
								.getAmount(), "验证用户账户流水表Amount");
					}
				}
				Logger.comment("校验ymt_orders表");
				Logger.verifyEquals(12,
						(Integer) ymtOrders.get(0).get("iTradingStatus"),
						"验证iTradingStatus");
				Logger.verifyEquals(null,
						ymtOrders.get(0).get("iSalesRefundStatus"),
						"验证iSalesRefundStatus");
				Logger.comment("校验ymt_orderstate表");
				Logger.verifyEquals(
						settlementInvoiceList
								.stream()
								.map(account -> (BigDecimal) account
										.get("CashAmount"))
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountOfCash"),
						"验证fRefundedAmountOfCash");
				Logger.verifyEquals(
						settlementInvoiceList
								.stream()
								.filter(account -> (Integer) account
										.get("BusinessType") == 2)
								.map(account -> (BigDecimal) account
										.get("CouponAmount"))
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountOfCoupon"),
						"验证fRefundedAmountOfCoupon");
				Logger.verifyEquals(
						settlementInvoiceList
								.stream()
								.filter(account -> (Integer) account
										.get("BusinessType") == 2)
								.map(account -> (BigDecimal) account
										.get("fAccountAmount"))
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountToAccount"),
						"验证fRefundedAmountToAccount");
				Logger.verifyEquals(null, (BigDecimal) ymtOrderState.get(0)
						.get("fRefundedPaidAmountToThirdParty"),
						"验证fRefundedPaidAmountToThirdParty");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SalesRefundSuccessRequest_011() {
		Logger.start(true, "全部第三方招行支付。确认收货前,订单多个商品依次全部全款退款");
		try {
			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder4();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			OrderCallService orderCallService = new OrderCallService();
			// 用余额支付金额
			BigDecimal blanceAmout = BigDecimal.ZERO;
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "50";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payType);
			// 支付网关支付回调交易
			PaymentProxyCallService.cmbNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			// 等待支付网关异步处理
			Thread.sleep(5000);
			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 申请退款
			applyRefundAllProduct(orderId);
			salesrefundsuccessrequestBean.setOperatorInfo("autotest");
			salesrefundsuccessrequestBean.setOrderId(orderId);
			salesrefundsuccessrequestBean.setRefundBillNo("TH0"
					+ String.valueOf(orderId));
			salesrefundsuccessrequestCall
					.setData(salesrefundsuccessrequestBean);
			Logger.comment("退该订单号" + orderId + "第一件商品");
			salesrefundsuccessrequestCall.callService();

			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");
			// 支付网关退款回调交易
			PaymentProxyCallService.refundNotifyCall(payType,
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			Thread.sleep(2000);
			salesrefundsuccessrequestBean.setOrderId(orderId);
			salesrefundsuccessrequestBean.setRefundBillNo("TH1"
					+ String.valueOf(orderId));
			salesrefundsuccessrequestCall
					.setData(salesrefundsuccessrequestBean);
			Logger.comment("退该订单号" + orderId + "第二件商品");

			salesrefundsuccessrequestCall.callService();

			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");

			// 支付网关退款回调交易
			PaymentProxyCallService.refundNotifyCall(payType,
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			Thread.sleep(3000);

			DefaultWapper defaultWapper = new DefaultWapper();
			if (salesrefundsuccessrequestCall.getReturnData().equals("ok")) {
				// 数据库验
				// 查询交易退款结算表
				Map m = new HashMap();

				m.put("orderId", orderId);

				// 查询交易退款结算表
				List<YmtSettlementInvoice> settlementInvoiceList = new YmtSettlementInvoiceWapper()
						.selectYmtSettlementInvoice(m);

				settlementInvoiceList = settlementInvoiceList.stream()
						.filter(item ->

						item.getBusinessType() != 14

						).collect(Collectors.toList());

				// 订单商品表
				List<Map> orderInfoList = defaultWapper
						.selectOrderInfoByOderId(orderId);
				// 订单主表
				List<Map> ymtOrders = defaultWapper
						.selectOrderByOderId(orderId);
				// ymtOrderState 表
				List<Map> ymtOrderState = defaultWapper
						.selectOrderStateByOderId(orderId);

				YmtRefundWapper ymtRefund = new YmtRefundWapper();

				for (int i = 0; i < orderInfoList.size(); i++) {
					// 订单退货记录
					YmtRefundBill refundBill = ymtRefund.selectRefundBill(m)
							.get(i);
					// 退货的商品记录
					YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(
							m).get(i);
					// 退款退货商品 catalogid
					String catalogId = refundPro.getCatalogId();
					/*
					 * // 商品使用的平台优惠券 BigDecimal productYmtCouponValue =
					 * BigDecimal.ZERO; for (Map m1 : orderInfoList) { if
					 * (((String) m1.get("sCatalogId")).equals(catalogId)) {
					 * productYmtCouponValue = (BigDecimal)
					 * m1.get("fYmtCouponAmount"); } }
					 */
					Logger.comment("校验订单号" + orderId + "第" + (i + 1) + "件商品");
					Logger.comment("校验Ymt_RefundBill表");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals("TH" + i + String.valueOf(orderId),
							refundBill.getRefundBillNo(), "验证RefundBillNo");
					Logger.verifyEquals(1, refundBill.getRefundStatus(),
							"验证RefundStatus");
					Logger.verifyEquals(1, refundBill.getSettlementStatus(),
							"验证SettlementStatus");
					Logger.verifyEquals(10, refundBill.getSalesRefundStatus(),
							"验证SalesRefundStatus");
					Logger.verifyEquals(1, refundBill.getRefundType(),
							"验证RefundType");
					Logger.verifyEquals("autotest refund",
							refundBill.getReason(), "验证Reason");
					// 退的平台优惠券
					/*
					 * Logger.verifyEquals(productYmtCouponValue,
					 * refundBill.getSettlementAmountOfCoupon(),
					 * "验证SettlementAmountOfCoupon");
					 */
					Logger.verifyEquals(sellerId, refundBill.getSellerId(),
							"验证SellerId");
					Logger.verifyEquals(userId, refundBill.getBuyerId(),
							"验证BuyerId");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.comment("校验Ymt_RefundProduct表");
					Logger.verifyEquals(orderId, refundPro.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals("TH" + i + String.valueOf(orderId),
							refundPro.getRefundBillNo(), "验证RefundBillNo");
					if (settlementInvoiceList.get(i).getBusinessNo()
							.equals(refundPro.getRefundBillNo())) {
						Logger.comment("校验Ymt_SettlementInvoice表");

						Logger.verifyEquals("TH" + i + String.valueOf(orderId),
								settlementInvoiceList.get(i).getBusinessNo(),
								"验证BusinessNo");
						Logger.verifyEquals(2, settlementInvoiceList.get(i)
								.getBusinessType(), "验证BusinessType");
						Logger.verifyEquals(orderId,
								settlementInvoiceList.get(i).getOrderId(),
								"验证OrderId");
						Logger.verifyEquals(
								(settlementInvoiceList.get(i).getCashAmount())

								.add(settlementInvoiceList.get(i)
										.getCouponAmount()).add(
										settlementInvoiceList.get(i)
												.getThirdPartyDiscountAmount()),

								settlementInvoiceList.get(i).getTotalAmount(),
								"验证TotalAmount");
						Logger.verifyEquals(refundBill.getRefundAmount(),
								settlementInvoiceList.get(i).getCashAmount(),
								"验证CashAmount");

						Logger.verifyEquals(sellerId, settlementInvoiceList
								.get(i).getSellerId(), "验证SellerId");
						Logger.verifyEquals("退款结算", settlementInvoiceList
								.get(i).getRemark(), "验证Remark");
						Logger.verifyEquals(1, settlementInvoiceList.get(i)
								.getSettlementStatus(), "验证SettlementStatus");
						Logger.verifyEquals(1, settlementInvoiceList.get(i)
								.getSettlementUser(), "验证SettlementUser");
						Logger.verifyEquals(null, settlementInvoiceList.get(i)
								.getProcessResult(), "验证ProcessResult");

						Logger.verifyEquals(refundBill
								.getRefundedDiscountOfThirdParty(),
								settlementInvoiceList.get(i)
										.getThirdPartyDiscountAmount(),
								"验证ThirdPartyDiscountAmount");

						Logger.comment("校验ymt_orderinfo表");
						Logger.verifyEquals(10, (Integer) orderInfoList.get(i)
								.get("iProductRefundStatus"),
								"验证iProductRefundStatus");
						// 资金流水表
						List<YmtAccountEntry> ymtActList = new AccountDefaultWapper()
								.selectAccountEntryByOriginalNo((String) settlementInvoiceList
										.get(i).getBusinessNo());
						List<YmtAccountEntry> userActList = ymtActList.stream()
								.filter(act -> act.getUserid() == userId)
								.collect(Collectors.toList());
						Logger.verifyEquals(((BigDecimal) settlementInvoiceList
								.get(i).getfAccountAmount())
								.compareTo(BigDecimal.ZERO) > 0 ? 1 : 0,
								userActList.size(), "验证用户账户流水表记录");
						List<YmtAccountEntry> sellerActList = ymtActList
								.stream()
								.filter(act -> act.getUserid() == sellerId)
								.collect(Collectors.toList());
						Logger.verifyEquals(0, sellerActList.size(),
								"验证商家账户流水表记录");
					}
				}
				Logger.comment("校验ymt_orders表");
				Logger.verifyEquals(12,
						(Integer) ymtOrders.get(0).get("iTradingStatus"),
						"验证iTradingStatus");
				Logger.verifyEquals(null,
						ymtOrders.get(0).get("iSalesRefundStatus"),
						"验证iSalesRefundStatus");
				Logger.comment("校验ymt_orderstate表");
				Logger.verifyEquals(
						settlementInvoiceList.stream()
								.map(account -> account.getCashAmount())
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountOfCash"),
						"验证fRefundedAmountOfCash");
				Logger.verifyEquals(null,
						ymtOrderState.get(0).get("fRefundedAmountToAccount"),
						"验证fRefundedAmountToAccount");
				Logger.verifyEquals(
						settlementInvoiceList.stream()
								.map(account -> account.getfThirdPartyAmount())
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedPaidAmountToThirdParty"),
						"验证fRefundedPaidAmountToThirdParty");
				Logger.verifyEquals(
						(BigDecimal) ymtOrderState.get(0).get(
								"fDiscountOfThirdParty"),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedDiscountOfThirdParty"),
						"验证fRefundedDiscountOfThirdParty");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SalesRefundSuccessRequest_012() {
		Logger.start(true, "余额+第三方招行混合支付。确认收货前,订单多个商品依次全部全款退款");
		try {

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder4();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			OrderCallService orderCallService = new OrderCallService();

			// 用余额支付金额
			BigDecimal blanceAmout = new BigDecimal(
					new Random().nextInt(50) + 1).setScale(2);
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "50";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payType);
			// 支付网关支付回调交易
			String cmbDiscountAmount = PaymentProxyCallService.cmbNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			// 等待支付网关异步处理
			Thread.sleep(5000);
			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 申请退款
			applyRefundAllProduct(orderId);
			salesrefundsuccessrequestBean.setOperatorInfo("autotest");
			salesrefundsuccessrequestBean.setOrderId(orderId);
			salesrefundsuccessrequestBean.setRefundBillNo("TH0"
					+ String.valueOf(orderId));
			salesrefundsuccessrequestCall
					.setData(salesrefundsuccessrequestBean);
			Logger.comment("退该订单号" + orderId + "第一件商品");
			salesrefundsuccessrequestCall.callService();
			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");

			salesrefundsuccessrequestBean.setOrderId(orderId);
			salesrefundsuccessrequestBean.setRefundBillNo("TH1"
					+ String.valueOf(orderId));
			salesrefundsuccessrequestCall
					.setData(salesrefundsuccessrequestBean);
			Logger.comment("退该订单号" + orderId + "第二件商品");
			salesrefundsuccessrequestCall.callService();
			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");

			// 支付网关退款回调交易
			PaymentProxyCallService.refundNotifyCall(payType,
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			Thread.sleep(5000);

			DefaultWapper defaultWapper = new DefaultWapper();
			if (salesrefundsuccessrequestCall.getReturnData().equals("ok")) {
				// 数据库验
				// 查询交易退款结算表
				Map m = new HashMap();

				m.put("orderId", orderId);

				// 查询交易退款结算表
				List<YmtSettlementInvoice> settlementInvoiceList = new YmtSettlementInvoiceWapper()
						.selectYmtSettlementInvoice(m);

				settlementInvoiceList = settlementInvoiceList.stream()
						.filter(item ->

						item.getBusinessType() != 14

						).collect(Collectors.toList());
				// 订单商品表
				List<Map> orderInfoList = defaultWapper
						.selectOrderInfoByOderId(orderId);
				// 订单主表
				List<Map> ymtOrders = defaultWapper
						.selectOrderByOderId(orderId);
				// ymtOrderState 表
				List<Map> ymtOrderState = defaultWapper
						.selectOrderStateByOderId(orderId);
				YmtRefundWapper ymtRefund = new YmtRefundWapper();
				// m.put("refundBillNo", refundBillNo);
				for (int i = 0; i < orderInfoList.size(); i++) {
					// 订单退货记录
					YmtRefundBill refundBill = ymtRefund.selectRefundBill(m)
							.get(i);
					// 退货的商品记录
					YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(
							m).get(i);
					// 退款退货商品 catalogid
					String catalogId = refundPro.getCatalogId();
					/*
					 * // 商品使用的平台优惠券 BigDecimal productYmtCouponValue =
					 * BigDecimal.ZERO; for (Map m1 : orderInfoList) { if
					 * (((String) m1.get("sCatalogId")).equals(catalogId)) {
					 * productYmtCouponValue = (BigDecimal)
					 * m1.get("fYmtCouponAmount"); } }
					 */
					Logger.comment("校验订单号" + orderId + "第" + (i + 1) + "件商品");
					Logger.comment("校验Ymt_RefundBill表");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals("TH" + i + String.valueOf(orderId),
							refundBill.getRefundBillNo(), "验证RefundBillNo");
					Logger.verifyEquals(1, refundBill.getRefundStatus(),
							"验证RefundStatus");
					Logger.verifyEquals(1, refundBill.getSettlementStatus(),
							"验证SettlementStatus");
					Logger.verifyEquals(10, refundBill.getSalesRefundStatus(),
							"验证SalesRefundStatus");
					Logger.verifyEquals(1, refundBill.getRefundType(),
							"验证RefundType");
					Logger.verifyEquals("autotest refund",
							refundBill.getReason(), "验证Reason");
					// 退的平台优惠券
					/*
					 * Logger.verifyEquals(productYmtCouponValue,
					 * refundBill.getSettlementAmountOfCoupon(),
					 * "验证SettlementAmountOfCoupon");
					 */
					Logger.verifyEquals(sellerId, refundBill.getSellerId(),
							"验证SellerId");
					Logger.verifyEquals(userId, refundBill.getBuyerId(),
							"验证BuyerId");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.comment("校验Ymt_RefundProduct表");
					Logger.verifyEquals(orderId, refundPro.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals("TH" + i + String.valueOf(orderId),
							refundPro.getRefundBillNo(), "验证RefundBillNo");
					if (settlementInvoiceList.get(i).getBusinessNo()
							.equals(refundPro.getRefundBillNo())) {
						Logger.comment("校验Ymt_SettlementInvoice表");

						Logger.verifyEquals("TH" + i + String.valueOf(orderId),
								settlementInvoiceList.get(i).getBusinessNo(),
								"验证BusinessNo");
						Logger.verifyEquals(2, settlementInvoiceList.get(i)
								.getBusinessType(), "验证BusinessType");
						Logger.verifyEquals(orderId,
								settlementInvoiceList.get(i).getOrderId(),
								"验证OrderId");
						Logger.verifyEquals(
								(settlementInvoiceList.get(i).getCashAmount())
										.add(settlementInvoiceList.get(i)
												.getCouponAmount())
										.add(settlementInvoiceList.get(i)
												.getThirdPartyDiscountAmount()),
								settlementInvoiceList.get(i).getTotalAmount(),
								"验证TotalAmount");
						Logger.verifyEquals(refundBill.getRefundAmount(),
								settlementInvoiceList.get(i).getCashAmount(),
								"验证CashAmount");

						Logger.verifyEquals(sellerId, settlementInvoiceList
								.get(i).getSellerId(), "验证SellerId");
						Logger.verifyEquals("退款结算", settlementInvoiceList
								.get(i).getRemark(), "验证Remark");
						Logger.verifyEquals(1, settlementInvoiceList.get(i)
								.getSettlementStatus(), "验证SettlementStatus");
						Logger.verifyEquals(1, settlementInvoiceList.get(i)
								.getSettlementUser(), "验证SettlementUser");
						Logger.verifyEquals(null, settlementInvoiceList.get(i)
								.getProcessResult(), "验证ProcessResult");

						Logger.verifyEquals(refundBill
								.getRefundedDiscountOfThirdParty(),
								settlementInvoiceList.get(i)
										.getThirdPartyDiscountAmount(),
								"验证ThirdPartyDiscountAmount");

						Logger.comment("校验ymt_orderinfo表");
						Logger.verifyEquals(10, (Integer) orderInfoList.get(i)
								.get("iProductRefundStatus"),
								"验证iProductRefundStatus");
						// 资金流水表
						List<YmtAccountEntry> ymtActList = new AccountDefaultWapper()
								.selectAccountEntryByOriginalNo(settlementInvoiceList
										.get(i).getBusinessNo());
						List<YmtAccountEntry> userActList = ymtActList.stream()
								.filter(act -> act.getUserid() == userId)
								.collect(Collectors.toList());
						Logger.verifyEquals(((BigDecimal) settlementInvoiceList
								.get(i).getfAccountAmount())
								.compareTo(BigDecimal.ZERO) > 0 ? 1 : 0,
								userActList.size(), "验证用户账户流水表记录");

					}
				}
				Logger.comment("校验ymt_orders表");
				Logger.verifyEquals(12,
						(Integer) ymtOrders.get(0).get("iTradingStatus"),
						"验证iTradingStatus");
				Logger.verifyEquals(null,
						ymtOrders.get(0).get("iSalesRefundStatus"),
						"验证iSalesRefundStatus");
				Logger.comment("校验ymt_orderstate表");
				Logger.verifyEquals(
						settlementInvoiceList
								.stream()
								.map(account -> (BigDecimal) account
										.getCashAmount())
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountOfCash"),
						"验证fRefundedAmountOfCash");
				Logger.verifyEquals(blanceAmout,
						ymtOrderState.get(0).get("fRefundedAmountToAccount"),
						"验证fRefundedAmountToAccount");
				Logger.verifyEquals(
						settlementInvoiceList
								.stream()
								.map(account -> (BigDecimal) account
										.getfThirdPartyAmount())
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedPaidAmountToThirdParty"),
						"验证fRefundedPaidAmountToThirdParty");

				Logger.verifyEquals(
						(BigDecimal) ymtOrderState.get(0).get(
								"fDiscountOfThirdParty"),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedDiscountOfThirdParty"),
						"验证fRefundedDiscountOfThirdParty");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SalesRefundSuccessRequest_013() {
		Logger.start(true, "余额+第三方招行混合支付。确认收货前,部分退款金额不大于账户余额支付金额");
		try {

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder4();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			OrderCallService orderCallService = new OrderCallService();

			// 用余额支付金额
			BigDecimal blanceAmout = new BigDecimal(
					new Random().nextInt(50) + 2).setScale(2);

			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "50";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payType);
			// 支付网关支付回调交易
			String cmbDiscountAmount = PaymentProxyCallService.cmbNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			// 等待支付网关异步处理
			Thread.sleep(5000);
			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 申请部分退款
			ApplySalesRefundRequestBean applySalesRefundRequestBean = new OrderCallService()
					.applySalesRefundRequestInJavaBean(orderId);

			applySalesRefundRequestBean.getSalesRefundInfoList().remove(1);

			applySalesRefundRequestBean.getSalesRefundInfoList().get(0)
					.setRefundAmount(blanceAmout);

			new OrderCallService()
					.applySalesRefundRequestCall(applySalesRefundRequestBean);

			salesrefundsuccessrequestBean.setOperatorInfo("autotest");
			salesrefundsuccessrequestBean.setOrderId(orderId);
			salesrefundsuccessrequestBean
					.setRefundBillNo(applySalesRefundRequestBean
							.getSalesRefundInfoList().get(0).getRefundBillNo());
			salesrefundsuccessrequestCall
					.setData(salesrefundsuccessrequestBean);
			Logger.comment("退该订单号" + orderId + "第一件商品");
			salesrefundsuccessrequestCall.callService();
			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");

			// 支付网关退款回调交易
			/*
			 * PaymentProxyCallService.refundNotifyCall(payType,
			 * String.valueOf(thirdTradingId), totalPrice.subtract(blanceAmout)
			 * .toString(), userId); Thread.sleep(5000);
			 */

			DefaultWapper defaultWapper = new DefaultWapper();
			if (salesrefundsuccessrequestCall.getReturnData().equals("ok")) {
				// 数据库验
				// 查询交易退款结算表
				List<Map> settlementInvoiceList = defaultWapper
						.selectYmtSettlementInvoice(orderId);
				// 订单商品表
				List<Map> orderInfoList = defaultWapper
						.selectOrderInfoByOderId(orderId);
				// 订单主表
				List<Map> ymtOrders = defaultWapper
						.selectOrderByOderId(orderId);
				// ymtOrderState 表
				List<Map> ymtOrderState = defaultWapper
						.selectOrderStateByOderId(orderId);
				YmtRefundWapper ymtRefund = new YmtRefundWapper();
				Map m = new HashMap();
				m.put("orderId", orderId);
				// m.put("refundBillNo", refundBillNo);
				// 订单退货记录
				YmtRefundBill refundBill = ymtRefund.selectRefundBill(m).get(0);
				// 退货的商品记录
				YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(m)
						.get(0);
				// 退款退货商品 catalogid
				String catalogId = refundPro.getCatalogId();
				/*
				 * // 商品使用的平台优惠券 BigDecimal productYmtCouponValue =
				 * BigDecimal.ZERO; for (Map m1 : orderInfoList) { if (((String)
				 * m1.get("sCatalogId")).equals(catalogId)) {
				 * productYmtCouponValue = (BigDecimal)
				 * m1.get("fYmtCouponAmount"); } }
				 */
				Logger.comment("校验订单号" + orderId + "第" + (0 + 1) + "件商品");
				Logger.comment("校验Ymt_RefundBill表");
				Logger.verifyEquals(orderId, refundBill.getOrderId(),
						"验证OrderId");
				Logger.verifyEquals("TH" + 0 + String.valueOf(orderId),
						refundBill.getRefundBillNo(), "验证RefundBillNo");
				Logger.verifyEquals(1, refundBill.getRefundStatus(),
						"验证RefundStatus");
				Logger.verifyEquals(1, refundBill.getSettlementStatus(),
						"验证SettlementStatus");
				Logger.verifyEquals(10, refundBill.getSalesRefundStatus(),
						"验证SalesRefundStatus");
				Logger.verifyEquals(1, refundBill.getRefundType(),
						"验证RefundType");
				Logger.verifyEquals("autotest refund", refundBill.getReason(),
						"验证Reason");
				// 退的平台优惠券
				/*
				 * Logger.verifyEquals(productYmtCouponValue,
				 * refundBill.getSettlementAmountOfCoupon(),
				 * "验证SettlementAmountOfCoupon");
				 */
				Logger.verifyEquals(sellerId, refundBill.getSellerId(),
						"验证SellerId");
				Logger.verifyEquals(userId, refundBill.getBuyerId(),
						"验证BuyerId");
				Logger.verifyEquals(orderId, refundBill.getOrderId(),
						"验证OrderId");
				Logger.comment("校验Ymt_RefundProduct表");
				Logger.verifyEquals(orderId, refundPro.getOrderId(),
						"验证OrderId");
				Logger.verifyEquals("TH" + 0 + String.valueOf(orderId),
						refundPro.getRefundBillNo(), "验证RefundBillNo");
				if (settlementInvoiceList.get(0).get("BusinessNo")
						.equals(refundPro.getRefundBillNo())) {
					Logger.comment("校验Ymt_SettlementInvoice表");

					Logger.verifyEquals(
							"TH" + 0 + String.valueOf(orderId),
							(String) settlementInvoiceList.get(0).get(
									"BusinessNo"), "验证BusinessNo");
					Logger.verifyEquals(
							2,
							(Integer) settlementInvoiceList.get(0).get(
									"BusinessType"), "验证BusinessType");
					Logger.verifyEquals(
							orderId,
							(Integer) settlementInvoiceList.get(0).get(
									"OrderId"), "验证OrderId");
					Logger.verifyEquals(
							((BigDecimal) settlementInvoiceList.get(0).get(
									"CashAmount")).add(
									(BigDecimal) settlementInvoiceList.get(0)
											.get("CouponAmount")).add(
									(BigDecimal) settlementInvoiceList.get(0)
											.get("ThirdPartyDiscountAmount")),
							(BigDecimal) settlementInvoiceList.get(0).get(
									"TotalAmount"), "验证TotalAmount");
					Logger.verifyEquals(
							refundBill.getRefundAmount(),
							(BigDecimal) settlementInvoiceList.get(0).get(
									"CashAmount"), "验证CashAmount");

					Logger.verifyEquals(
							sellerId,
							(Integer) settlementInvoiceList.get(0).get(
									"SellerId"), "验证SellerId");
					Logger.verifyEquals("退款结算", (String) settlementInvoiceList
							.get(0).get("Remark"), "验证Remark");
					Logger.verifyEquals(
							1,
							(Integer) settlementInvoiceList.get(0).get(
									"SettlementStatus"), "验证SettlementStatus");
					Logger.verifyEquals(
							1,
							(Integer) settlementInvoiceList.get(0).get(
									"SettlementUser"), "验证SettlementUser");
					Logger.verifyEquals(null, (String) settlementInvoiceList
							.get(0).get("ProcessResult"), "验证ProcessResult");

					Logger.verifyEquals(
							refundBill.getRefundedDiscountOfThirdParty(),
							(BigDecimal) settlementInvoiceList.get(0).get(
									"ThirdPartyDiscountAmount"),
							"验证ThirdPartyDiscountAmount");

					Logger.comment("校验ymt_orderinfo表");
					Logger.verifyEquals(
							10,
							(Integer) orderInfoList.get(0).get(
									"iProductRefundStatus"),
							"验证iProductRefundStatus");
					// 资金流水表
					List<YmtAccountEntry> ymtActList = new AccountDefaultWapper()
							.selectAccountEntryByOriginalNo((String) settlementInvoiceList
									.get(0).get("BusinessNo"));
					List<YmtAccountEntry> userActList = ymtActList.stream()
							.filter(act -> act.getUserid() == userId)
							.collect(Collectors.toList());
					Logger.verifyEquals(((BigDecimal) settlementInvoiceList
							.get(0).get("fAccountAmount"))
							.compareTo(BigDecimal.ZERO) > 0 ? 1 : 0,
							userActList.size(), "验证用户账户流水表记录");
					List<YmtAccountEntry> sellerActList = ymtActList.stream()
							.filter(act -> act.getUserid() == sellerId)
							.collect(Collectors.toList());
					Logger.verifyEquals(0, sellerActList.size(), "验证商家账户流水表记录");

				}
				Logger.comment("校验ymt_orders表");

				Logger.verifyEquals(17,
						(Integer) ymtOrders.get(0).get("iTradingStatus"),
						"验证iTradingStatus");
				Logger.verifyEquals(null,
						ymtOrders.get(0).get("iSalesRefundStatus"),
						"验证iSalesRefundStatus");
				Logger.comment("校验ymt_orderstate表");
				Logger.verifyEquals(
						settlementInvoiceList
								.stream()
								.map(account -> (BigDecimal) account
										.get("CashAmount"))
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountOfCash"),
						"验证fRefundedAmountOfCash");
				Logger.verifyEquals(blanceAmout,
						ymtOrderState.get(0).get("fRefundedAmountToAccount"),
						"验证fRefundedAmountToAccount");
				Logger.verifyEquals(
						null,
						ymtOrderState.get(0).get(
								"fRefundedPaidAmountToThirdParty"),
						"验证fRefundedPaidAmountToThirdParty");

				Logger.verifyEquals(BigDecimal.ZERO.setScale(2), ymtOrderState
						.get(0).get("fRefundedDiscountOfThirdParty"),
						"验证fRefundedDiscountOfThirdParty");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SalesRefundSuccessRequest_014() {
		Logger.start(true, "余额+第三方招行混合支付。确认收货前,部分退款金额大于账户余额支付金额");
		try {

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder4();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			OrderCallService orderCallService = new OrderCallService();

			// 用余额支付金额
			BigDecimal blanceAmout = new BigDecimal(
					new Random().nextInt(100) + 2).setScale(2);
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "50";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payType);
			// 支付网关支付回调交易
			String cmbDiscountAmount = PaymentProxyCallService.cmbNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			// 等待支付网关异步处理
			Thread.sleep(5000);
			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 申请部分退款
			ApplySalesRefundRequestBean applySalesRefundRequestBean = new OrderCallService()
					.applySalesRefundRequestInJavaBean(orderId);

			applySalesRefundRequestBean.getSalesRefundInfoList().remove(1);

			applySalesRefundRequestBean.getSalesRefundInfoList().get(0)
					.setRefundAmount(blanceAmout.add(new BigDecimal(30)));

			new OrderCallService()
					.applySalesRefundRequestCall(applySalesRefundRequestBean);

			salesrefundsuccessrequestBean.setOperatorInfo("autotest");
			salesrefundsuccessrequestBean.setOrderId(orderId);
			salesrefundsuccessrequestBean
					.setRefundBillNo(applySalesRefundRequestBean
							.getSalesRefundInfoList().get(0).getRefundBillNo());
			salesrefundsuccessrequestCall
					.setData(salesrefundsuccessrequestBean);
			Logger.comment("退该订单号" + orderId + "第一件商品");
			salesrefundsuccessrequestCall.callService();
			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");

			Thread.sleep(3000);

			// 支付网关退款回调交易
			PaymentProxyCallService.refundNotifyCall(payType,
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			Thread.sleep(2000);

			DefaultWapper defaultWapper = new DefaultWapper();
			if (salesrefundsuccessrequestCall.getReturnData().equals("ok")) {
				// 数据库验
				// 查询交易退款结算表
				List<Map> settlementInvoiceList = defaultWapper
						.selectYmtSettlementInvoice(orderId);
				// 订单商品表
				List<Map> orderInfoList = defaultWapper
						.selectOrderInfoByOderId(orderId);
				// 订单主表
				List<Map> ymtOrders = defaultWapper
						.selectOrderByOderId(orderId);
				// ymtOrderState 表
				List<Map> ymtOrderState = defaultWapper
						.selectOrderStateByOderId(orderId);
				YmtRefundWapper ymtRefund = new YmtRefundWapper();
				Map m = new HashMap();
				m.put("orderId", orderId);
				// m.put("refundBillNo", refundBillNo);
				// 订单退货记录
				YmtRefundBill refundBill = ymtRefund.selectRefundBill(m).get(0);
				// 退货的商品记录
				YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(m)
						.get(0);
				// 退款退货商品 catalogid
				String catalogId = refundPro.getCatalogId();
				/*
				 * // 商品使用的平台优惠券 BigDecimal productYmtCouponValue =
				 * BigDecimal.ZERO; for (Map m1 : orderInfoList) { if (((String)
				 * m1.get("sCatalogId")).equals(catalogId)) {
				 * productYmtCouponValue = (BigDecimal)
				 * m1.get("fYmtCouponAmount"); } }
				 */
				Logger.comment("校验订单号" + orderId + "第" + (0 + 1) + "件商品");
				Logger.comment("校验Ymt_RefundBill表");
				Logger.verifyEquals(orderId, refundBill.getOrderId(),
						"验证OrderId");
				Logger.verifyEquals("TH" + 0 + String.valueOf(orderId),
						refundBill.getRefundBillNo(), "验证RefundBillNo");
				Logger.verifyEquals(1, refundBill.getRefundStatus(),
						"验证RefundStatus");
				Logger.verifyEquals(1, refundBill.getSettlementStatus(),
						"验证SettlementStatus");
				Logger.verifyEquals(10, refundBill.getSalesRefundStatus(),
						"验证SalesRefundStatus");
				Logger.verifyEquals(1, refundBill.getRefundType(),
						"验证RefundType");
				Logger.verifyEquals("autotest refund", refundBill.getReason(),
						"验证Reason");
				// 退的平台优惠券
				/*
				 * Logger.verifyEquals(productYmtCouponValue,
				 * refundBill.getSettlementAmountOfCoupon(),
				 * "验证SettlementAmountOfCoupon");
				 */
				Logger.verifyEquals(sellerId, refundBill.getSellerId(),
						"验证SellerId");
				Logger.verifyEquals(userId, refundBill.getBuyerId(),
						"验证BuyerId");
				Logger.verifyEquals(orderId, refundBill.getOrderId(),
						"验证OrderId");
				Logger.comment("校验Ymt_RefundProduct表");
				Logger.verifyEquals(orderId, refundPro.getOrderId(),
						"验证OrderId");
				Logger.verifyEquals("TH" + 0 + String.valueOf(orderId),
						refundPro.getRefundBillNo(), "验证RefundBillNo");
				if (settlementInvoiceList.get(0).get("BusinessNo")
						.equals(refundPro.getRefundBillNo())) {
					Logger.comment("校验Ymt_SettlementInvoice表");

					Logger.verifyEquals(
							"TH" + 0 + String.valueOf(orderId),
							(String) settlementInvoiceList.get(0).get(
									"BusinessNo"), "验证BusinessNo");
					Logger.verifyEquals(
							2,
							(Integer) settlementInvoiceList.get(0).get(
									"BusinessType"), "验证BusinessType");
					Logger.verifyEquals(
							orderId,
							(Integer) settlementInvoiceList.get(0).get(
									"OrderId"), "验证OrderId");
					Logger.verifyEquals(
							((BigDecimal) settlementInvoiceList.get(0).get(
									"CashAmount")).add(
									(BigDecimal) settlementInvoiceList.get(0)
											.get("CouponAmount")).add(
									(BigDecimal) settlementInvoiceList.get(0)
											.get("ThirdPartyDiscountAmount")),
							(BigDecimal) settlementInvoiceList.get(0).get(
									"TotalAmount"), "验证TotalAmount");
					Logger.verifyEquals(
							refundBill.getRefundAmount(),
							(BigDecimal) settlementInvoiceList.get(0).get(
									"CashAmount"), "验证CashAmount");

					Logger.verifyEquals(
							sellerId,
							(Integer) settlementInvoiceList.get(0).get(
									"SellerId"), "验证SellerId");
					Logger.verifyEquals("退款结算", (String) settlementInvoiceList
							.get(0).get("Remark"), "验证Remark");
					Logger.verifyEquals(
							1,
							(Integer) settlementInvoiceList.get(0).get(
									"SettlementStatus"), "验证SettlementStatus");
					Logger.verifyEquals(
							1,
							(Integer) settlementInvoiceList.get(0).get(
									"SettlementUser"), "验证SettlementUser");
					Logger.verifyEquals(null, (String) settlementInvoiceList
							.get(0).get("ProcessResult"), "验证ProcessResult");

					Logger.verifyEquals(
							refundBill.getRefundedDiscountOfThirdParty(),
							(BigDecimal) settlementInvoiceList.get(0).get(
									"ThirdPartyDiscountAmount"),
							"验证ThirdPartyDiscountAmount");

					Logger.comment("校验ymt_orderinfo表");
					Logger.verifyEquals(
							10,
							(Integer) orderInfoList.get(0).get(
									"iProductRefundStatus"),
							"验证iProductRefundStatus");
					// 资金流水表
					List<YmtAccountEntry> ymtActList = new AccountDefaultWapper()
							.selectAccountEntryByOriginalNo((String) settlementInvoiceList
									.get(0).get("BusinessNo"));
					List<YmtAccountEntry> userActList = ymtActList.stream()
							.filter(act -> act.getUserid() == userId)
							.collect(Collectors.toList());
					Logger.verifyEquals(((BigDecimal) settlementInvoiceList
							.get(0).get("fAccountAmount"))
							.compareTo(BigDecimal.ZERO) > 0 ? 1 : 0,
							userActList.size(), "验证用户账户流水表记录");
					List<YmtAccountEntry> sellerActList = ymtActList.stream()
							.filter(act -> act.getUserid() == sellerId)
							.collect(Collectors.toList());
					Logger.verifyEquals(0, sellerActList.size(), "验证商家账户流水表记录");

				}
				Logger.comment("校验ymt_orders表");

				Logger.verifyEquals(17,
						(Integer) ymtOrders.get(0).get("iTradingStatus"),
						"验证iTradingStatus");
				Logger.verifyEquals(null,
						ymtOrders.get(0).get("iSalesRefundStatus"),
						"验证iSalesRefundStatus");
				Logger.comment("校验ymt_orderstate表");
				Logger.verifyEquals(
						settlementInvoiceList
								.stream()
								.map(account -> (BigDecimal) account
										.get("CashAmount"))
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountOfCash"),
						"验证fRefundedAmountOfCash");
				Logger.verifyEquals(blanceAmout,
						ymtOrderState.get(0).get("fRefundedAmountToAccount"),
						"验证fRefundedAmountToAccount");
				Logger.verifyEquals(
						new BigDecimal(30).setScale(2),
						ymtOrderState.get(0).get(
								"fRefundedPaidAmountToThirdParty"),
						"验证fRefundedPaidAmountToThirdParty");

				BigDecimal cmbDiscount = new BigDecimal(cmbDiscountAmount)
						.setScale(2);
				BigDecimal cmbPayAmout = (BigDecimal) ymtOrderState.get(0).get(
						"fPaidAmountOfThirdParty");

				// 招商银行补贴金额按退款的第三方金额比例退
				Logger.verifyEquals(
						new BigDecimal(30).multiply(cmbDiscount).divide(
								cmbPayAmout, 2, BigDecimal.ROUND_DOWN),
						ymtOrderState.get(0).get(
								"fRefundedDiscountOfThirdParty"),
						"验证fRefundedDiscountOfThirdParty");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SalesRefundSuccessRequest_015() {
		Logger.start(true, "余额+第三方招行混合支付, 大于账户余额支付金额,在确认收货");
		try {

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder7();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			OrderCallService orderCallService = new OrderCallService();

			// 用余额支付金额
			BigDecimal blanceAmout = new BigDecimal(
					new Random().nextInt(100) + 2).setScale(2);

			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "50";
			int thirdTradingId = orderCallService.orderPayRequest(userId,
					blanceAmout, tradingId, payType);
			// 支付网关支付回调交易
			String cmbDiscountAmount = PaymentProxyCallService.cmbNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			// 等待支付网关异步处理
			Thread.sleep(5000);

			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 申请部分退款
			ApplySalesRefundRequestBean applySalesRefundRequestBean = new OrderCallService()
					.applySalesRefundRequestInJavaBean(orderId);

			//只退第一个商品
			applySalesRefundRequestBean.getSalesRefundInfoList().remove(1);
			applySalesRefundRequestBean.getSalesRefundInfoList().remove(1);

			//退款金额
			BigDecimal partRefundAmount = placeOrderResp.getOrderList().get(0)
					.getOrderInfoList().get(0).getProductPrice();

			applySalesRefundRequestBean.getSalesRefundInfoList().get(0)
					.setRefundAmount(partRefundAmount);

			new OrderCallService()
					.applySalesRefundRequestCall(applySalesRefundRequestBean);

			salesrefundsuccessrequestBean.setOperatorInfo("autotest");
			salesrefundsuccessrequestBean.setOrderId(orderId);
			salesrefundsuccessrequestBean
					.setRefundBillNo(applySalesRefundRequestBean
							.getSalesRefundInfoList().get(0).getRefundBillNo());
			salesrefundsuccessrequestCall
					.setData(salesrefundsuccessrequestBean);

			Logger.comment("退该订单号" + orderId + "第一件商品");
			salesrefundsuccessrequestCall.callService();
			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");

			// 支付网关退款回调交易
			PaymentProxyCallService.refundNotifyCall(payType,
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			Thread.sleep(5000);
			// 发货
			orderCallService.dispatched(orderId, sellerId);
			// 确认收货
			orderCallService.confirmReceive(userId, orderId);
			// 确认收货发mq消息生成结算单
			Thread.sleep(5000);
			// 对结算单进行结算
			settlesellerIncome(orderId);

			DefaultWapper defaultWapper = new DefaultWapper();

			if (salesrefundsuccessrequestCall.getReturnData().equals("ok")) {

				// 查询交易退款结算表
				Map m = new HashMap();

				m.put("orderId", orderId);

				// 查询交易退款结算表
				List<YmtSettlementInvoice> settlementInvoiceList = new YmtSettlementInvoiceWapper()
						.selectYmtSettlementInvoice(m);

				settlementInvoiceList = settlementInvoiceList.stream()
						.filter(item ->

						item.getBusinessType() != 14

						).collect(Collectors.toList());

				// 订单商品表
				List<Map> orderInfoList = defaultWapper
						.selectOrderInfoByOderId(orderId);
				// 订单主表
				List<Map> ymtOrders = defaultWapper
						.selectOrderByOderId(orderId);
				// ymtOrderState 表
				List<Map> ymtOrderState = defaultWapper
						.selectOrderStateByOderId(orderId);

				YmtRefundWapper ymtRefund = new YmtRefundWapper();

				m.put("refundBillNo",
						salesrefundsuccessrequestBean.getRefundBillNo());
				// 订单退货记录

				YmtRefundBill refundBill = ymtRefund.selectRefundBill(m).get(0);
				// 退货的商品记录

				YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(m)
						.get(0);
				// 退款退货商品 catalogid
				String catalogId = refundPro.getCatalogId();

				Logger.comment("校验订单号" + orderId + "第" + (0 + 1) + "件商品");
				Logger.comment("校验Ymt_RefundBill表");
				Logger.verifyEquals(orderId, refundBill.getOrderId(),
						"验证OrderId");
				Logger.verifyEquals("TH" + 0 + String.valueOf(orderId),
						refundBill.getRefundBillNo(), "验证RefundBillNo");
				DataUtil.verifyDecimalEquals(partRefundAmount,
						refundBill.getRefundAmount(), "验证RefundAmount");
				Logger.verifyEquals(1, refundBill.getRefundStatus(),
						"验证RefundStatus");
				Logger.verifyEquals(1, refundBill.getSettlementStatus(),
						"验证SettlementStatus");
				Logger.verifyEquals(10, refundBill.getSalesRefundStatus(),
						"验证SalesRefundStatus");
				Logger.verifyEquals(1, refundBill.getRefundType(),
						"验证RefundType");
				Logger.verifyEquals("autotest refund", refundBill.getReason(),
						"验证Reason");

				Logger.verifyEquals(sellerId, refundBill.getSellerId(),
						"验证SellerId");
				Logger.verifyEquals(userId, refundBill.getBuyerId(),
						"验证BuyerId");
				Logger.verifyEquals(orderId, refundBill.getOrderId(),
						"验证OrderId");
				Logger.comment("校验Ymt_RefundProduct表");
				Logger.verifyEquals(orderId, refundPro.getOrderId(),
						"验证OrderId");
				Logger.verifyEquals("TH" + 0 + String.valueOf(orderId),
						refundPro.getRefundBillNo(), "验证RefundBillNo");

				if (settlementInvoiceList.get(0).getBusinessNo()
						.equals(refundPro.getRefundBillNo())) {

					Logger.comment("校验Ymt_SettlementInvoice 退款结算单");

					Logger.verifyEquals("TH" + 0 + String.valueOf(orderId),
							settlementInvoiceList.get(0).getBusinessNo(),
							"验证BusinessNo");
					Logger.verifyEquals(2, settlementInvoiceList.get(0)
							.getBusinessType(), "验证BusinessType");
					Logger.verifyEquals(orderId, settlementInvoiceList.get(0)
							.getOrderId(), "验证OrderId");
					Logger.verifyEquals(
							(settlementInvoiceList.get(0).getCashAmount()).add(
									settlementInvoiceList.get(0)
											.getCouponAmount()).add(
									settlementInvoiceList.get(0)
											.getThirdPartyDiscountAmount()),
							settlementInvoiceList.get(0).getTotalAmount(),
							"验证TotalAmount");
					Logger.verifyEquals(refundBill.getRefundAmount(),
							settlementInvoiceList.get(0).getCashAmount(),
							"验证Ymt_SettlementInvoice 结算单CashAmount");

					Logger.verifyEquals(sellerId, settlementInvoiceList.get(0)
							.getSellerId(), "验证SellerId");
					Logger.verifyEquals("退款结算", settlementInvoiceList.get(0)
							.getRemark(), "验证Remark");
					Logger.verifyEquals(1, settlementInvoiceList.get(0)
							.getSettlementStatus(), "验证SettlementStatus");
					Logger.verifyEquals(1, settlementInvoiceList.get(0)
							.getSettlementUser(), "验证SettlementUser");
					Logger.verifyEquals(null, settlementInvoiceList.get(0)
							.getProcessResult(), "验证ProcessResult");

					/*					Logger.verifyEquals(
												new BigDecimal(30).setScale(2),
												(BigDecimal) settlementInvoiceList.get(0).get(
														"fThirdPartyAmount"), "验证fThirdPartyAmount");*/

					Logger.verifyEquals(refundBill
							.getRefundedDiscountOfThirdParty(),
							settlementInvoiceList.get(0)
									.getThirdPartyDiscountAmount(),
							"验证ThirdPartyDiscountAmount");

					Logger.comment("校验ymt_orderinfo表");
					Logger.verifyEquals(
							10,
							(Integer) orderInfoList.get(0).get(
									"iProductRefundStatus"),
							"验证iProductRefundStatus");

				}
				// 确认收货结算单
				List<YmtSettlementInvoice> settlementConfirm = settlementInvoiceList
						.stream().filter(s -> s.getBusinessType() == 1)
						.collect(Collectors.toList());

				if (settlementConfirm.size() > 0) {

					Logger.comment("校验Ymt_SettlementInvoice 确认收货结算单");

					Logger.verifyEquals(String.valueOf(orderId),
							settlementConfirm.get(0).getBusinessNo(),
							"验证BusinessNo");
					Logger.verifyEquals(orderId, settlementConfirm.get(0)
							.getOrderId(), "验证OrderId");

					Logger.verifyEquals(
							(settlementConfirm.get(0).getCashAmount()).add(
									settlementConfirm.get(0).getCouponAmount())
									.add(settlementConfirm.get(0)
											.getThirdPartyDiscountAmount()),
							settlementConfirm.get(0).getTotalAmount(),
							"验证TotalAmount");

					Logger.verifyEquals(
							((BigDecimal) ymtOrderState.get(0).get(
									"fPaidAmountOfCash")).subtract(refundBill
									.getRefundAmount()),
							settlementConfirm.get(0).getCashAmount(),
							"验证确认收货结算单CashAmount");

					Logger.verifyEquals(sellerId, settlementConfirm.get(0)
							.getSellerId(), "验证SellerId");
					Logger.verifyEquals("确认收货订单结算", settlementConfirm.get(0)
							.getRemark(), "验证Remark");
					Logger.verifyEquals(1, settlementConfirm.get(0)
							.getSettlementStatus(), "验证SettlementStatus");
					Logger.verifyEquals(2, settlementConfirm.get(0)
							.getSettlementUser(), "验证SettlementUser");
					Logger.verifyEquals(null, settlementConfirm.get(0)
							.getProcessResult(), "验证ProcessResult");

					Logger.verifyEquals(
							((BigDecimal) ymtOrderState.get(0).get(
									"fDiscountOfThirdParty"))
									.subtract(refundBill
											.getRefundedDiscountOfThirdParty()),
							settlementConfirm.get(0)
									.getThirdPartyDiscountAmount(),
							"验证ThirdPartyDiscountAmount");

					Logger.comment("校验ymt_orderinfo表");
					Logger.verifyEquals(
							10,
							(Integer) orderInfoList.get(0).get(
									"iProductRefundStatus"),
							"验证iProductRefundStatus");
					// 支付后金额
					Map act = new HashMap();
					act.put("userId", sellerId);
					// 确认收货流水
					act.put("originalNo", String.valueOf(orderId));

					List<YmtAccountEntry> actinfos = new AccountDefaultWapper()
							.selectAccountEntryByBizNo(act);
					BigDecimal accountEntryPrice = actinfos.stream()
							.map(a -> a.getAmount())
							.reduce(BigDecimal.ZERO, BigDecimal::add);

					// 支付网关充值流水
					Logger.verifyEquals(settlementConfirm.get(0)
							.getTotalAmount(), accountEntryPrice,
							"验证商家账户资金订单确认收货收入流水金额");

				}

				Logger.comment("校验ymt_orders表");

				Logger.verifyEquals(4,
						(Integer) ymtOrders.get(0).get("iTradingStatus"),
						"验证iTradingStatus");
				Logger.verifyEquals(null,
						ymtOrders.get(0).get("iSalesRefundStatus"),
						"验证iSalesRefundStatus");
				Logger.comment("校验ymt_orderstate表");

				Logger.verifyEquals(
						settlementInvoiceList
								.stream()
								.filter(account -> account.getBusinessType() == 2)
								.map(account -> account.getCashAmount())
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountOfCash"),
						"验证fRefundedAmountOfCash");

				Logger.verifyEquals(
						settlementInvoiceList
								.stream()
								.filter(account -> account.getBusinessType() == 2)
								.map(account -> account.getfAccountAmount())
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						ymtOrderState.get(0).get("fRefundedAmountToAccount"),
						"验证fRefundedAmountToAccount");

				Logger.verifyEquals(
						settlementInvoiceList
								.stream()
								.filter(account -> account.getBusinessType() == 2)
								.map(account -> account.getfThirdPartyAmount())
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						ymtOrderState.get(0).get(
								"fRefundedPaidAmountToThirdParty"),
						"验证fRefundedPaidAmountToThirdParty");

				// 招商银行补贴金额按退款的第三方金额比例退
				Logger.verifyEquals(
						refundBill.getRefundedDiscountOfThirdParty(),
						ymtOrderState.get(0).get(
								"fRefundedDiscountOfThirdParty"),
						"验证fRefundedDiscountOfThirdParty");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_SalesRefundSuccessRequest_016() {
		Logger.start(true, "余额+第三方招行混合支付,确认收货后发起退款,部分退款金额大于账户余额支付金额");
		try {

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder4();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			OrderCallService orderCallService = new OrderCallService();
			// 用余额支付金额
			BigDecimal blanceAmout = new BigDecimal(21.00);

			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "50";
			int thirdTradingId = orderCallService.orderPayRequest(userId,
					blanceAmout, tradingId, payType);
			// 支付网关支付回调交易
			String cmbDiscountAmount = PaymentProxyCallService.cmbNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			// 等待支付网关异步处理
			Thread.sleep(5000);
			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 发货
			orderCallService.dispatched(orderId, sellerId);
			// 确认收货
			orderCallService.confirmReceive(userId, orderId);
			// 确认收货发mq消息生成结算单
			Thread.sleep(5000);

			// 对结算单进行结算
			settlesellerIncome(orderId);

			// 申请部分退款
			ApplySalesRefundRequestBean applySalesRefundRequestBean = new OrderCallService()
					.applySalesRefundRequestInJavaBean(orderId);

			applySalesRefundRequestBean.getSalesRefundInfoList().remove(1);

			SalesRefundInfoBean salesRefundInfoBean = applySalesRefundRequestBean
					.getSalesRefundInfoList().get(0);

			salesRefundInfoBean.setRefundAmount(salesRefundInfoBean
					.getRefundAmount().subtract(new BigDecimal(10)));

			new OrderCallService()
					.applySalesRefundRequestCall(applySalesRefundRequestBean);

			salesrefundsuccessrequestBean.setOperatorInfo("autotest");
			salesrefundsuccessrequestBean.setOrderId(orderId);
			salesrefundsuccessrequestBean
					.setRefundBillNo(applySalesRefundRequestBean
							.getSalesRefundInfoList().get(0).getRefundBillNo());
			salesrefundsuccessrequestCall
					.setData(salesrefundsuccessrequestBean);
			Logger.comment("退该订单号" + orderId + "第一件商品");
			salesrefundsuccessrequestCall.callService();
			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");

			// 支付网关退款回调交易
			PaymentProxyCallService.refundNotifyCall(payType,
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			Thread.sleep(5000);
			DefaultWapper defaultWapper = new DefaultWapper();
			if (salesrefundsuccessrequestCall.getReturnData().equals("ok")) {
				// 数据库验
				// 查询交易退款结算表
				List<Map> settlementInvoiceList = defaultWapper
						.selectYmtSettlementInvoice(orderId);
				// 订单商品表
				List<Map> orderInfoList = defaultWapper
						.selectOrderInfoByOderId(orderId);
				// 订单主表
				List<Map> ymtOrders = defaultWapper
						.selectOrderByOderId(orderId);
				// ymtOrderState 表
				List<Map> ymtOrderState = defaultWapper
						.selectOrderStateByOderId(orderId);

				// 确认收货结算单
				List<Map> settlementConfirm = settlementInvoiceList.stream()
						.filter(s -> (Integer) s.get("BusinessType") == 1)
						.collect(Collectors.toList());
				if (settlementConfirm.size() > 0) {
					Logger.comment("校验Ymt_SettlementInvoice 确认收货结算单");

					Logger.verifyEquals(
							String.valueOf(orderId),
							(String) settlementConfirm.get(0).get("BusinessNo"),
							"验证BusinessNo");
					Logger.verifyEquals(orderId, (Integer) settlementConfirm
							.get(0).get("OrderId"), "验证OrderId");
					Logger.verifyEquals(
							((BigDecimal) settlementConfirm.get(0).get(
									"CashAmount")).add(
									(BigDecimal) settlementConfirm.get(0).get(
											"CouponAmount")).add(
									(BigDecimal) settlementConfirm.get(0).get(
											"ThirdPartyDiscountAmount")),
							(BigDecimal) settlementConfirm.get(0).get(
									"TotalAmount"), "验证TotalAmount");
					Logger.verifyEquals(totalPrice.subtract(new BigDecimal(
							cmbDiscountAmount)), (BigDecimal) settlementConfirm
							.get(0).get("CashAmount"), "验证CashAmount");

					Logger.verifyEquals(sellerId, (Integer) settlementConfirm
							.get(0).get("SellerId"), "验证SellerId");
					Logger.verifyEquals("确认收货订单结算", (String) settlementConfirm
							.get(0).get("Remark"), "验证Remark");
					Logger.verifyEquals(1, (Integer) settlementConfirm.get(0)
							.get("SettlementStatus"), "验证SettlementStatus");
					Logger.verifyEquals(2, (Integer) settlementConfirm.get(0)
							.get("SettlementUser"), "验证SettlementUser");
					Logger.verifyEquals(null, (String) settlementConfirm.get(0)
							.get("ProcessResult"), "验证ProcessResult");

					Logger.verifyEquals(
							new BigDecimal(cmbDiscountAmount).setScale(2),
							(BigDecimal) settlementConfirm.get(0).get(
									"ThirdPartyDiscountAmount"),
							"验证ThirdPartyDiscountAmount");

					Logger.comment("校验ymt_orderinfo表");
					Logger.verifyEquals(
							10,
							(Integer) orderInfoList.get(0).get(
									"iProductRefundStatus"),
							"验证iProductRefundStatus");
				}

				YmtRefundWapper ymtRefund = new YmtRefundWapper();
				Map m = new HashMap();
				m.put("orderId", orderId);
				// m.put("refundBillNo", refundBillNo);
				// 订单退货记录
				YmtRefundBill refundBill = ymtRefund.selectRefundBill(m).get(0);
				// 退货的商品记录
				YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(m)
						.get(0);

				// 退款退货商品 catalogid
				String catalogId = refundPro.getCatalogId();
				/*
				 * // 商品使用的平台优惠券 BigDecimal productYmtCouponValue =
				 * BigDecimal.ZERO; for (Map m1 : orderInfoList) { if (((String)
				 * m1.get("sCatalogId")).equals(catalogId)) {
				 * productYmtCouponValue = (BigDecimal)
				 * m1.get("fYmtCouponAmount"); } }
				 */
				Logger.comment("校验订单号" + orderId + "第" + (0 + 1) + "件商品");
				Logger.comment("校验Ymt_RefundBill表");
				Logger.verifyEquals(orderId, refundBill.getOrderId(),
						"验证OrderId");
				Logger.verifyEquals("TH" + 0 + String.valueOf(orderId),
						refundBill.getRefundBillNo(), "验证RefundBillNo");
				Logger.verifyEquals(1, refundBill.getRefundStatus(),
						"验证RefundStatus");
				Logger.verifyEquals(1, refundBill.getSettlementStatus(),
						"验证SettlementStatus");
				Logger.verifyEquals(10, refundBill.getSalesRefundStatus(),
						"验证SalesRefundStatus");
				Logger.verifyEquals(1, refundBill.getRefundType(),
						"验证RefundType");
				Logger.verifyEquals("autotest refund", refundBill.getReason(),
						"验证Reason");
				// 退的平台优惠券
				/*
				 * Logger.verifyEquals(productYmtCouponValue,
				 * refundBill.getSettlementAmountOfCoupon(),
				 * "验证SettlementAmountOfCoupon");
				 */
				Logger.verifyEquals(sellerId, refundBill.getSellerId(),
						"验证SellerId");
				Logger.verifyEquals(userId, refundBill.getBuyerId(),
						"验证BuyerId");
				Logger.verifyEquals(orderId, refundBill.getOrderId(),
						"验证OrderId");

				Logger.verifyEquals(true, refundBill.isTopspeedRefund(),
						"验证OrderId");

				Logger.comment("校验Ymt_RefundProduct表");
				Logger.verifyEquals(orderId, refundPro.getOrderId(),
						"验证OrderId");
				Logger.verifyEquals("TH" + 0 + String.valueOf(orderId),
						refundPro.getRefundBillNo(), "验证RefundBillNo");

				// 确认收货结算单
				List<Map> settlementRefund = settlementInvoiceList.stream()
						.filter(s -> (Integer) s.get("BusinessType") == 2)
						.collect(Collectors.toList());
				if (settlementRefund.size() > 0) {
					Logger.comment("校验Ymt_SettlementInvoice 退款结算单");

					Logger.verifyEquals("TH" + 0 + String.valueOf(orderId),
							(String) settlementRefund.get(0).get("BusinessNo"),
							"验证BusinessNo");
					Logger.verifyEquals(2, (Integer) settlementRefund.get(0)
							.get("BusinessType"), "验证BusinessType");
					Logger.verifyEquals(orderId, (Integer) settlementRefund
							.get(0).get("OrderId"), "验证OrderId");
					Logger.verifyEquals(
							((BigDecimal) settlementRefund.get(0).get(
									"CashAmount")).add(
									(BigDecimal) settlementRefund.get(0).get(
											"CouponAmount")).add(
									(BigDecimal) settlementRefund.get(0).get(
											"ThirdPartyDiscountAmount")),
							(BigDecimal) settlementRefund.get(0).get(
									"TotalAmount"), "验证TotalAmount");
					Logger.verifyEquals(
							refundBill.getRefundAmount(),
							(BigDecimal) settlementRefund.get(0).get(
									"CashAmount"), "验证CashAmount");

					Logger.verifyEquals(sellerId, (Integer) settlementRefund
							.get(0).get("SellerId"), "验证SellerId");
					Logger.verifyEquals("退款结算", (String) settlementRefund
							.get(0).get("Remark"), "验证Remark");
					Logger.verifyEquals(1, (Integer) settlementRefund.get(0)
							.get("SettlementStatus"), "验证SettlementStatus");
					Logger.verifyEquals(2, (Integer) settlementRefund.get(0)
							.get("SettlementUser"), "验证SettlementUser");
					Logger.verifyEquals(null, (String) settlementRefund.get(0)
							.get("ProcessResult"), "验证ProcessResult");

					Logger.verifyEquals(
							refundBill.getRefundedDiscountOfThirdParty(),
							(BigDecimal) settlementRefund.get(0).get(
									"ThirdPartyDiscountAmount"),
							"验证ThirdPartyDiscountAmount");

					Logger.comment("校验ymt_orderinfo表");
					Logger.verifyEquals(
							10,
							(Integer) orderInfoList.get(0).get(
									"iProductRefundStatus"),
							"验证iProductRefundStatus");

					// 支付后金额
					Map act = new HashMap();
					act.put("userId", sellerId);
					// 确认收货流水
					act.put("originalNo", String.valueOf(orderId));

					List<YmtAccountEntry> actinfos = new AccountDefaultWapper()
							.selectAccountEntryByBizNo(act);
					BigDecimal accountEntryPrice = actinfos.stream()
							.map(a -> a.getAmount())
							.reduce(BigDecimal.ZERO, BigDecimal::add);

					// 支付网关充值流水
					Logger.verifyEquals((BigDecimal) settlementConfirm.get(0)
							.get("TotalAmount"), accountEntryPrice,
							"验证商家账户资金订单确认收货收入流水金额");

					act.put("userId", userId);
					// 退款流水
					act.put("originalNo",
							(String) settlementRefund.get(0).get("BusinessNo"));
					List<YmtAccountEntry> refundActinfos = new AccountDefaultWapper()
							.selectAccountEntryByBizNo(act);
					BigDecimal accountEntryRefund = refundActinfos.stream()
							.map(a -> a.getAmount())
							.reduce(BigDecimal.ZERO, BigDecimal::add);

					// 用户账户退款退余额部分流水
					Logger.verifyEquals((BigDecimal) settlementRefund.get(0)
							.get("fAccountAmount"), accountEntryRefund,
							"验证用户账户资金退款收入流水金额");

					act.put("userId", sellerId);
					// 退款流水
					act.put("originalNo",
							(String) settlementRefund.get(0).get("BusinessNo"));
					List<YmtAccountEntry> sellerRefundActinfos = new AccountDefaultWapper()
							.selectAccountEntryByBizNo(act);
					BigDecimal sellerAccountEntryRefund = sellerRefundActinfos
							.stream().map(a -> a.getAmount())
							.reduce(BigDecimal.ZERO, BigDecimal::add);

					// 商家账户退款扣除流水
					Logger.verifyEquals(((BigDecimal) settlementRefund.get(0)
							.get("TotalAmount")).divide(new BigDecimal(-1)),
							sellerAccountEntryRefund, "验证用户账户资金退款收入流水金额");

				}

				Logger.comment("校验ymt_orders表");

				Logger.verifyEquals(4,
						(Integer) ymtOrders.get(0).get("iTradingStatus"),
						"验证iTradingStatus");
				Logger.verifyEquals(null,
						ymtOrders.get(0).get("iSalesRefundStatus"),
						"验证iSalesRefundStatus");
				Logger.comment("校验ymt_orderstate表");

				Logger.verifyEquals(
						settlementInvoiceList
								.stream()
								.filter(account -> (Integer) account
										.get("BusinessType") == 2)
								.map(account -> (BigDecimal) account
										.get("CashAmount"))
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountOfCash"),
						"验证fRefundedAmountOfCash");

			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SalesRefundSuccessRequest_017() {
		Logger.start(true, "全部第三方招行支付。确认收货前,订单一个商品全部全款退款");
		try {
			OrderCallService orderCallService = new OrderCallService();
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 用余额支付金额
			BigDecimal blanceAmout = BigDecimal.ZERO;
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "50";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payType);
			// 支付网关支付回调交易
			String cmbDiscountAmount = PaymentProxyCallService.cmbNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			// 等待支付网关异步处理
			Thread.sleep(5000);
			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 申请退款
			applyRefundAllProduct(orderId);
			salesrefundsuccessrequestBean.setOperatorInfo("autotest");
			salesrefundsuccessrequestBean.setOrderId(orderId);
			salesrefundsuccessrequestBean.setRefundBillNo("TH0"
					+ String.valueOf(orderId));
			salesrefundsuccessrequestCall
					.setData(salesrefundsuccessrequestBean);
			Logger.comment("退该订单号" + orderId + "第一件商品");
			salesrefundsuccessrequestCall.callService();
			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");

			// 支付网关退款回调交易
			PaymentProxyCallService.refundNotifyCall(payType,
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);

			Thread.sleep(3000);

			DefaultWapper defaultWapper = new DefaultWapper();
			if (salesrefundsuccessrequestCall.getReturnData().equals("ok")) {
				// 数据库验
				// 查询交易退款结算表
				Map m = new HashMap();

				m.put("orderId", orderId);

				// 查询交易退款结算表
				List<YmtSettlementInvoice> settlementInvoiceList = new YmtSettlementInvoiceWapper()
						.selectYmtSettlementInvoice(m);

				settlementInvoiceList = settlementInvoiceList.stream()
						.filter(item ->

						item.getBusinessType() != 14

						).collect(Collectors.toList());
				// 订单商品表
				List<Map> orderInfoList = defaultWapper
						.selectOrderInfoByOderId(orderId);
				// 订单主表
				List<Map> ymtOrders = defaultWapper
						.selectOrderByOderId(orderId);
				// ymtOrderState 表
				List<Map> ymtOrderState = defaultWapper
						.selectOrderStateByOderId(orderId);
				YmtRefundWapper ymtRefund = new YmtRefundWapper();

				// m.put("refundBillNo", refundBillNo);
				for (int i = 0; i < orderInfoList.size(); i++) {
					// 订单退货记录
					YmtRefundBill refundBill = ymtRefund.selectRefundBill(m)
							.get(i);
					// 退货的商品记录
					YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(
							m).get(i);
					// 退款退货商品 catalogid
					String catalogId = refundPro.getCatalogId();
					/*
					 * // 商品使用的平台优惠券 BigDecimal productYmtCouponValue =
					 * BigDecimal.ZERO; for (Map m1 : orderInfoList) { if
					 * (((String) m1.get("sCatalogId")).equals(catalogId)) {
					 * productYmtCouponValue = (BigDecimal)
					 * m1.get("fYmtCouponAmount"); } }
					 */
					Logger.comment("校验订单号" + orderId + "第" + (i + 1) + "件商品");
					Logger.comment("校验Ymt_RefundBill表");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals("TH" + i + String.valueOf(orderId),
							refundBill.getRefundBillNo(), "验证RefundBillNo");
					Logger.verifyEquals(1, refundBill.getRefundStatus(),
							"验证RefundStatus");
					Logger.verifyEquals(1, refundBill.getSettlementStatus(),
							"验证SettlementStatus");
					Logger.verifyEquals(10, refundBill.getSalesRefundStatus(),
							"验证SalesRefundStatus");
					Logger.verifyEquals(1, refundBill.getRefundType(),
							"验证RefundType");
					Logger.verifyEquals("autotest refund",
							refundBill.getReason(), "验证Reason");
					// 退的平台优惠券
					/*
					 * Logger.verifyEquals(productYmtCouponValue,
					 * refundBill.getSettlementAmountOfCoupon(),
					 * "验证SettlementAmountOfCoupon");
					 */
					Logger.verifyEquals(sellerId, refundBill.getSellerId(),
							"验证SellerId");
					Logger.verifyEquals(userId, refundBill.getBuyerId(),
							"验证BuyerId");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.comment("校验Ymt_RefundProduct表");
					Logger.verifyEquals(orderId, refundPro.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals("TH" + i + String.valueOf(orderId),
							refundPro.getRefundBillNo(), "验证RefundBillNo");
					if (settlementInvoiceList.get(i).getBusinessNo()
							.equals(refundPro.getRefundBillNo())) {
						Logger.comment("校验Ymt_SettlementInvoice表");

						Logger.verifyEquals("TH" + i + String.valueOf(orderId),
								settlementInvoiceList.get(i).getBusinessNo(),
								"验证BusinessNo");
						Logger.verifyEquals(2, settlementInvoiceList.get(i)
								.getBusinessType(), "验证BusinessType");
						Logger.verifyEquals(orderId,
								settlementInvoiceList.get(i).getOrderId(),
								"验证OrderId");
						Logger.verifyEquals(
								(settlementInvoiceList.get(i).getCashAmount())
										.add(settlementInvoiceList.get(i)
												.getCouponAmount())
										.add(settlementInvoiceList.get(i)
												.getThirdPartyDiscountAmount()),
								settlementInvoiceList.get(i).getTotalAmount(),
								"验证TotalAmount");
						Logger.verifyEquals(refundBill.getRefundAmount(),
								settlementInvoiceList.get(i).getCashAmount(),
								"验证CashAmount");

						Logger.verifyEquals(sellerId, settlementInvoiceList
								.get(i).getSellerId(), "验证SellerId");
						Logger.verifyEquals("退款结算", settlementInvoiceList
								.get(i).getRemark(), "验证Remark");
						Logger.verifyEquals(1, settlementInvoiceList.get(i)
								.getSettlementStatus(), "验证SettlementStatus");
						Logger.verifyEquals(1, settlementInvoiceList.get(i)
								.getSettlementUser(), "验证SettlementUser");
						Logger.verifyEquals(null, settlementInvoiceList.get(i)
								.getProcessResult(), "验证ProcessResult");

						Logger.verifyEquals(refundBill
								.getRefundedDiscountOfThirdParty(),
								settlementInvoiceList.get(i)
										.getThirdPartyDiscountAmount(),
								"验证ThirdPartyDiscountAmount");

						Logger.comment("校验ymt_orderinfo表");
						Logger.verifyEquals(10, (Integer) orderInfoList.get(i)
								.get("iProductRefundStatus"),
								"验证iProductRefundStatus");
						// 资金流水表
						List<YmtAccountEntry> ymtActList = new AccountDefaultWapper()
								.selectAccountEntryByOriginalNo(settlementInvoiceList
										.get(i).getBusinessNo());
						List<YmtAccountEntry> userActList = ymtActList.stream()
								.filter(act -> act.getUserid() == userId)
								.collect(Collectors.toList());
						Logger.verifyEquals((settlementInvoiceList.get(i)
								.getfAccountAmount())
								.compareTo(BigDecimal.ZERO) > 0 ? 1 : 0,
								userActList.size(), "验证用户账户流水表记录");
						List<YmtAccountEntry> sellerActList = ymtActList
								.stream()
								.filter(act -> act.getUserid() == sellerId)
								.collect(Collectors.toList());
						Logger.verifyEquals(0, sellerActList.size(),
								"验证商家账户流水表记录");
					}
				}
				Logger.comment("校验ymt_orders表");
				Logger.verifyEquals(12,
						(Integer) ymtOrders.get(0).get("iTradingStatus"),
						"验证iTradingStatus");
				Logger.verifyEquals(null,
						ymtOrders.get(0).get("iSalesRefundStatus"),
						"验证iSalesRefundStatus");
				Logger.comment("校验ymt_orderstate表");
				Logger.verifyEquals(
						settlementInvoiceList.stream()
								.map(account -> account.getCashAmount())
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountOfCash"),
						"验证fRefundedAmountOfCash");
				Logger.verifyEquals(null,
						ymtOrderState.get(0).get("fRefundedAmountToAccount"),
						"验证fRefundedAmountToAccount");
				Logger.verifyEquals(
						settlementInvoiceList.stream()
								.map(account -> account.getfThirdPartyAmount())
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedPaidAmountToThirdParty"),
						"验证fRefundedPaidAmountToThirdParty");
				Logger.verifyEquals(
						(BigDecimal) ymtOrderState.get(0).get(
								"fDiscountOfThirdParty"),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedDiscountOfThirdParty"),
						"验证fRefundedDiscountOfThirdParty");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SalesRefundSuccessRequest_018() {
		Logger.start(true, "全部第三方招行支付,一个订单一个商品,接单后商品货全部退完，还有金额没退完的，订单状态为用户取消。");
		try {
			OrderCallService orderCallService = new OrderCallService();
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 用余额支付金额
			BigDecimal blanceAmout = BigDecimal.ZERO;
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "50";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payType);
			// 支付网关支付回调交易
			String cmbDiscountAmount = PaymentProxyCallService.cmbNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			// 等待支付网关异步处理
			Thread.sleep(5000);
			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);

			// 申请退款
			ApplySalesRefundRequestBean applysalesrefundrequestBean = orderCallService
					.applySalesRefundRequestInJavaBean(orderId);

			applysalesrefundrequestBean.getSalesRefundInfoList().forEach(
					refund -> refund.setRefundAmount(refund.getRefundAmount()
							.subtract(BigDecimal.TEN)));
			// 申请退款
			orderCallService
					.applySalesRefundRequestCall(applysalesrefundrequestBean);

			String refundBillNo = "TH0" + String.valueOf(orderId);

			salesrefundsuccessrequestBean.setOperatorInfo("autotest");
			salesrefundsuccessrequestBean.setOrderId(orderId);
			salesrefundsuccessrequestBean.setRefundBillNo(refundBillNo);
			salesrefundsuccessrequestCall
					.setData(salesrefundsuccessrequestBean);

			Logger.comment("退该订单号" + orderId + "第一件商品");
			salesrefundsuccessrequestCall.callService();
			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");

			// 支付网关退款回调交易
			PaymentProxyCallService.refundNotifyCall(payType,
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			Thread.sleep(5000);

			settleLeftAmtAfterCancelled(orderId);

			DefaultWapper defaultWapper = new DefaultWapper();

			if (salesrefundsuccessrequestCall.getReturnData().equals("ok")) {
				// 数据库验
				// 查询交易退款结算表
				List<Map> settlementInvoiceList = defaultWapper
						.selectYmtSettlementInvoice(orderId);
				// 订单商品表
				List<Map> orderInfoList = defaultWapper
						.selectOrderInfoByOderId(orderId);
				// 订单主表
				List<Map> ymtOrders = defaultWapper
						.selectOrderByOderId(orderId);
				// ymtOrderState 表
				List<Map> ymtOrderState = defaultWapper
						.selectOrderStateByOderId(orderId);

				// 订单退货退款结算
				List<Map> settlementInvoiceList1 = settlementInvoiceList
						.stream()
						.filter(m -> (Integer) m.get("BusinessType") == 2)
						.collect(Collectors.toList());
				// 订单已取消订单剩余金额结算
				List<Map> settlementInvoiceList2 = settlementInvoiceList
						.stream()
						.filter(m -> (Integer) m.get("BusinessType") == 7)
						.collect(Collectors.toList());

				Logger.comment("校验Ymt_SettlementInvoice表");

				Logger.verifyEquals(1, (Integer) settlementInvoiceList2.get(0)
						.get("SettlementStatus"), "验证SettlementStatus");
				Logger.verifyEquals(2, (Integer) settlementInvoiceList2.get(0)
						.get("SettlementUser"), "验证SettlementUser");
				Logger.verifyEquals("已取消订单剩余金额结算",
						(String) settlementInvoiceList2.get(0).get("Remark"),
						"验证Remark");

				// 商家资金流水表
				List<YmtAccountEntry> ymtActList = new AccountDefaultWapper()
						.selectAccountEntryByOriginalNo((String) settlementInvoiceList2
								.get(0).get("BusinessNo"));

				if (ymtActList.size() > 0) {
					Logger.comment("校验Ymt_AccountEntry表");
					Logger.verifyEquals((BigDecimal) settlementInvoiceList2
							.get(0).get("TotalAmount"), ymtActList.get(0)
							.getAmount(), "验证商家账户流水表Amount");
				}

				Logger.comment("校验ymt_orders表");
				Logger.verifyEquals(12,
						(Integer) ymtOrders.get(0).get("iTradingStatus"),
						"验证iTradingStatus");
				Logger.verifyEquals(null,
						ymtOrders.get(0).get("iSalesRefundStatus"),
						"验证iSalesRefundStatus");
				Logger.comment("校验ymt_orderstate表");
				Logger.verifyEquals(
						settlementInvoiceList
								.stream()
								.map(account -> (BigDecimal) account
										.get("CashAmount"))
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fPaidAmountOfCash"), "验证fPaidAmountOfCash");

				Logger.verifyEquals((BigDecimal) settlementInvoiceList1.get(0)
						.get("CashAmount"), (BigDecimal) ymtOrderState.get(0)
						.get("fRefundedAmountOfCash"),
						"验证fRefundedAmountOfCash");
				Logger.verifyEquals((BigDecimal) settlementInvoiceList1.get(0)
						.get("CouponAmount"), (BigDecimal) ymtOrderState.get(0)
						.get("fRefundedAmountOfCoupon"),
						"验证fRefundedAmountOfCoupon");

				DataUtil.verifyDecimalEquals(null,
						ymtOrderState.get(0).get("fRefundedAmountToAccount"),
						"验证fRefundedAmountToAccount");
				Logger.verifyEquals((BigDecimal) settlementInvoiceList1.get(0)
						.get("fThirdPartyAmount"), (BigDecimal) ymtOrderState
						.get(0).get("fRefundedPaidAmountToThirdParty"),
						"验证fRefundedPaidAmountToThirdParty");
			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SalesRefundSuccessRequest_019() {
		Logger.start(true, "组合支付,接单后,一个订单多个商品，货全部退完,订单状态为用户取消，还有部分金额给商家结算");
		try {

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder4();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			OrderCallService orderCallService = new OrderCallService();
			// 用余额支付金额
			BigDecimal blanceAmout = new BigDecimal(32);
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "13";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payType);
			// 支付网关支付回调交易
			PaymentProxyCallService.notifyCall(payType,
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			// 等待支付网关异步处理
			Thread.sleep(5000);
			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);

			BigDecimal applyRefundAmout = new BigDecimal(130);

			// 申请退款
			ApplySalesRefundRequestBean applysalesrefundrequestBean = orderCallService
					.applySalesRefundRequestInJavaBean(orderId);

			applysalesrefundrequestBean.getSalesRefundInfoList().forEach(
					refund -> refund.setRefundAmount(refund.getRefundAmount()
							.subtract(BigDecimal.TEN)));

			// 申请退款
			orderCallService
					.applySalesRefundRequestCall(applysalesrefundrequestBean);

			String refundBillNo1 = "TH0" + String.valueOf(orderId);
			String refundBillNo2 = "TH1" + String.valueOf(orderId);
			// 退款执行
			orderCallService
					.salesrefundsuccessrequest(applysalesrefundrequestBean);

			// 支付网关退款回调交易
			PaymentProxyCallService.refundNotifyCall(payType,
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			Thread.sleep(5000);

			// 对结算单进行结算
			settleLeftAmtAfterCancelled(orderId);

			DefaultWapper defaultWapper = new DefaultWapper();

			// 数据库验
			// 查询交易退款结算表
			List<Map> settlementInvoiceList = defaultWapper
					.selectYmtSettlementInvoice(orderId);
			// 订单商品表
			List<Map> orderInfoList = defaultWapper
					.selectOrderInfoByOderId(orderId);
			// 订单主表
			List<Map> ymtOrders = defaultWapper.selectOrderByOderId(orderId);
			// ymtOrderState 表
			List<Map> ymtOrderState = defaultWapper
					.selectOrderStateByOderId(orderId);

			// 订单退货退款结算
			List<Map> settlementInvoiceList1 = settlementInvoiceList.stream()
					.filter(m -> (Integer) m.get("BusinessType") == 2)
					.collect(Collectors.toList());
			// 订单已取消订单剩余金额结算
			List<Map> settlementInvoiceList2 = settlementInvoiceList.stream()
					.filter(m -> (Integer) m.get("BusinessType") == 7)
					.collect(Collectors.toList());

			Logger.comment("校验Ymt_SettlementInvoice表");

			Logger.verifyEquals(
					1,
					(Integer) settlementInvoiceList2.get(0).get(
							"SettlementStatus"), "验证SettlementStatus");
			Logger.verifyEquals(
					2,
					(Integer) settlementInvoiceList2.get(0).get(
							"SettlementUser"), "验证SettlementUser");
			Logger.verifyEquals("已取消订单剩余金额结算", (String) settlementInvoiceList2
					.get(0).get("Remark"), "验证Remark");

			// 商家资金流水表
			List<YmtAccountEntry> ymtActList = new AccountDefaultWapper()
					.selectAccountEntryByOriginalNo((String) settlementInvoiceList2
							.get(0).get("BusinessNo"));

			if (ymtActList.size() > 0) {
				Logger.comment("校验Ymt_AccountEntry表");
				Logger.verifyEquals((BigDecimal) settlementInvoiceList2.get(0)
						.get("TotalAmount"), ymtActList.get(0).getAmount(),
						"验证商家账户流水表Amount");
			}

			Logger.comment("校验ymt_orders表");
			Logger.verifyEquals(12,
					(Integer) ymtOrders.get(0).get("iTradingStatus"),
					"验证iTradingStatus");
			Logger.verifyEquals(null, ymtOrders.get(0)
					.get("iSalesRefundStatus"), "验证iSalesRefundStatus");
			Logger.comment("校验ymt_orderstate表");
			Logger.verifyEquals(
					settlementInvoiceList
							.stream()
							.map(account -> (BigDecimal) account
									.get("CashAmount"))
							.reduce(BigDecimal.ZERO, BigDecimal::add),
					(BigDecimal) ymtOrderState.get(0).get("fPaidAmountOfCash"),
					"验证fPaidAmountOfCash");

			Logger.verifyEquals(
					settlementInvoiceList1
							.stream()
							.map(account -> (BigDecimal) account
									.get("CashAmount"))
							.reduce(BigDecimal.ZERO, BigDecimal::add),
					(BigDecimal) ymtOrderState.get(0).get(
							"fRefundedAmountOfCash"), "验证fRefundedAmountOfCash");
			Logger.verifyEquals(
					settlementInvoiceList1
							.stream()
							.map(account -> (BigDecimal) account
									.get("CouponAmount"))
							.reduce(BigDecimal.ZERO, BigDecimal::add),
					(BigDecimal) ymtOrderState.get(0).get(
							"fRefundedAmountOfCoupon"),
					"验证fRefundedAmountOfCoupon");

			DataUtil.verifyDecimalEquals(

					settlementInvoiceList1
							.stream()
							.map(account -> (BigDecimal) account
									.get("fAccountAmount"))
							.reduce(BigDecimal.ZERO, BigDecimal::add)

					, ymtOrderState.get(0).get("fRefundedAmountToAccount"),
					"验证fRefundedAmountToAccount");
			Logger.verifyEquals(
					settlementInvoiceList1
							.stream()
							.map(account -> (BigDecimal) account
									.get("fThirdPartyAmount"))
							.reduce(BigDecimal.ZERO, BigDecimal::add)

					,
					(BigDecimal) ymtOrderState.get(0).get(
							"fRefundedPaidAmountToThirdParty"),
					"验证fRefundedPaidAmountToThirdParty");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_SalesRefundSuccessRequest_020() {
		Logger.start(true, "全部第三方招行支付,一个订单一个商品,接单后,货跟款都没有全部退完的");
		try {
			OrderCallService orderCallService = new OrderCallService();

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder4();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 用余额支付金额
			BigDecimal blanceAmout = BigDecimal.ZERO;
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "50";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payType);
			// 支付网关支付回调交易
			String cmbDiscountAmount = PaymentProxyCallService.cmbNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			// 等待支付网关异步处理
			Thread.sleep(5000);
			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);

			// 申请退款
			ApplySalesRefundRequestBean applysalesrefundrequestBean = orderCallService
					.applySalesRefundRequestInJavaBean(orderId);

			// 货跟款都是部分退
			applysalesrefundrequestBean.getSalesRefundInfoList()
					.forEach(
							refund -> {
								refund.setRefundProductNum(refund
										.getRefundProductNum() - 1);
								refund.setRefundAmount(new BigDecimal(17));
							});
			// 申请退款
			orderCallService
					.applySalesRefundRequestCall(applysalesrefundrequestBean);

			salesrefundsuccessrequestBean.setOperatorInfo("autotest");
			salesrefundsuccessrequestBean.setOrderId(orderId);
			salesrefundsuccessrequestBean.setRefundBillNo("TH0"
					+ String.valueOf(orderId));
			salesrefundsuccessrequestCall
					.setData(salesrefundsuccessrequestBean);

			Logger.comment("退该订单号" + orderId + "第一件商品");
			salesrefundsuccessrequestCall.callService();
			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");

			Thread.sleep(3000);

			// 支付网关退款回调交易
			PaymentProxyCallService.refundNotifyCall(payType,
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			Thread.sleep(3000);

			DefaultWapper defaultWapper = new DefaultWapper();
			if (salesrefundsuccessrequestCall.getReturnData().equals("ok")) {
				// 数据库验
				// 查询交易退款结算表
				Map m = new HashMap();

				m.put("orderId", orderId);
				m.put("businessType", 2);

				// 查询交易退款结算表
				List<YmtSettlementInvoice> settlementInvoiceList = new YmtSettlementInvoiceWapper()
						.selectYmtSettlementInvoice(m);

				// 订单商品表
				List<Map> orderInfoList = defaultWapper
						.selectOrderInfoByOderId(orderId);
				// 订单主表
				List<Map> ymtOrders = defaultWapper
						.selectOrderByOderId(orderId);
				// ymtOrderState 表
				List<Map> ymtOrderState = defaultWapper
						.selectOrderStateByOderId(orderId);
				YmtRefundWapper ymtRefund = new YmtRefundWapper();

				// m.put("refundBillNo", refundBillNo);
				for (int i = 0; i < settlementInvoiceList.size(); i++) {
					// 订单退货记录
					YmtRefundBill refundBill = ymtRefund.selectRefundBill(m)
							.get(i);
					// 退货的商品记录
					YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(
							m).get(i);
					// 退款退货商品 catalogid
					String catalogId = refundPro.getCatalogId();

					Logger.comment("校验订单号" + orderId + "第" + (i + 1) + "件商品");
					Logger.comment("校验Ymt_RefundBill表");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals("TH" + i + String.valueOf(orderId),
							refundBill.getRefundBillNo(), "验证RefundBillNo");
					Logger.verifyEquals(1, refundBill.getRefundStatus(),
							"验证RefundStatus");
					Logger.verifyEquals(1, refundBill.getSettlementStatus(),
							"验证SettlementStatus");
					Logger.verifyEquals(10, refundBill.getSalesRefundStatus(),
							"验证SalesRefundStatus");
					Logger.verifyEquals(1, refundBill.getRefundType(),
							"验证RefundType");
					Logger.verifyEquals("autotest refund",
							refundBill.getReason(), "验证Reason");

					Logger.verifyEquals(sellerId, refundBill.getSellerId(),
							"验证SellerId");
					Logger.verifyEquals(userId, refundBill.getBuyerId(),
							"验证BuyerId");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");

					Logger.comment("校验Ymt_RefundProduct表");

					Logger.verifyEquals(orderId, refundPro.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals("TH" + i + String.valueOf(orderId),
							refundPro.getRefundBillNo(), "验证RefundBillNo");

					if (settlementInvoiceList.get(i).getBusinessNo()
							.equals(refundPro.getRefundBillNo())) {

						Logger.comment("校验Ymt_SettlementInvoice表");

						Logger.verifyEquals("TH" + i + String.valueOf(orderId),
								settlementInvoiceList.get(i).getBusinessNo(),
								"验证BusinessNo");
						Logger.verifyEquals(2, settlementInvoiceList.get(i)
								.getBusinessType(), "验证BusinessType");
						Logger.verifyEquals(orderId,
								settlementInvoiceList.get(i).getOrderId(),
								"验证OrderId");
						Logger.verifyEquals(
								(settlementInvoiceList.get(i).getCashAmount())
										.add(settlementInvoiceList.get(i)
												.getCouponAmount())
										.add(settlementInvoiceList.get(i)
												.getThirdPartyDiscountAmount()),
								settlementInvoiceList.get(i).getTotalAmount(),
								"验证TotalAmount");
						Logger.verifyEquals(refundBill.getRefundAmount(),
								settlementInvoiceList.get(i).getCashAmount(),
								"验证CashAmount");

						Logger.verifyEquals(sellerId, settlementInvoiceList
								.get(i).getSellerId(), "验证SellerId");
						Logger.verifyEquals("退款结算", settlementInvoiceList
								.get(i).getRemark(), "验证Remark");
						Logger.verifyEquals(1, settlementInvoiceList.get(i)
								.getSettlementStatus(), "验证SettlementStatus");
						Logger.verifyEquals(1, settlementInvoiceList.get(i)
								.getSettlementUser(), "验证SettlementUser");
						Logger.verifyEquals(null, settlementInvoiceList.get(i)
								.getProcessResult(), "验证ProcessResult");

						Logger.verifyEquals(refundBill
								.getRefundedDiscountOfThirdParty(),
								settlementInvoiceList.get(i)
										.getThirdPartyDiscountAmount(),
								"验证ThirdPartyDiscountAmount");

						Logger.comment("校验ymt_orderinfo表");
						Logger.verifyEquals(10, (Integer) orderInfoList.get(i)
								.get("iProductRefundStatus"),
								"验证iProductRefundStatus");
						// 资金流水表
						List<YmtAccountEntry> ymtActList = new AccountDefaultWapper()
								.selectAccountEntryByOriginalNo(settlementInvoiceList
										.get(i).getBusinessNo());
						List<YmtAccountEntry> userActList = ymtActList.stream()
								.filter(act -> act.getUserid() == userId)
								.collect(Collectors.toList());
						Logger.verifyEquals((settlementInvoiceList.get(i)
								.getfAccountAmount())
								.compareTo(BigDecimal.ZERO) > 0 ? 1 : 0,
								userActList.size(), "验证用户账户流水表记录");
						List<YmtAccountEntry> sellerActList = ymtActList
								.stream()
								.filter(act -> act.getUserid() == sellerId)
								.collect(Collectors.toList());
						Logger.verifyEquals(0, sellerActList.size(),
								"验证商家账户流水表记录");
					}
				}
				Logger.comment("校验ymt_orders表");
				Logger.verifyEquals(17,
						(Integer) ymtOrders.get(0).get("iTradingStatus"),
						"验证iTradingStatus");
				Logger.verifyEquals(null,
						ymtOrders.get(0).get("iSalesRefundStatus"),
						"验证iSalesRefundStatus");
				Logger.comment("校验ymt_orderstate表");
				Logger.verifyEquals(
						settlementInvoiceList.stream()
								.map(account -> account.getCashAmount())
								.reduce(BigDecimal.ZERO, BigDecimal::add)
								.setScale(2), (BigDecimal) ymtOrderState.get(0)
								.get("fRefundedAmountOfCash"),
						"验证fRefundedAmountOfCash");
				Logger.verifyEquals(null,
						ymtOrderState.get(0).get("fRefundedAmountToAccount"),
						"验证fRefundedAmountToAccount");
				Logger.verifyEquals(
						settlementInvoiceList.stream()
								.map(account -> account.getfThirdPartyAmount())
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedPaidAmountToThirdParty"),
						"验证fRefundedPaidAmountToThirdParty");

			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_SalesRefundSuccessRequest_021() {
		Logger.start(true, "全部第三方招行支付,一个订单一个商品,订单已发货，货全部取消,还有金额没退的。订单状态不变");
		try {
			OrderCallService orderCallService = new OrderCallService();
			PlaceOrderResp placeOrderResp = new OrderCallService()
					.createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额
			// 用余额支付金额
			BigDecimal blanceAmout = BigDecimal.ZERO;
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "50";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payType);
			// 支付网关支付回调交易
			String cmbDiscountAmount = PaymentProxyCallService.cmbNotifyCall(
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			// 等待支付网关异步处理
			Thread.sleep(5000);
			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 发货
			orderCallService.dispatched(orderId, sellerId);

			// 申请退款
			ApplySalesRefundRequestBean applysalesrefundrequestBean = orderCallService
					.applySalesRefundRequestInJavaBean(orderId);

			applysalesrefundrequestBean.getSalesRefundInfoList().forEach(
					refund -> refund.setRefundAmount(refund.getRefundAmount()
							.subtract(BigDecimal.TEN)));
			// 申请退款
			orderCallService
					.applySalesRefundRequestCall(applysalesrefundrequestBean);

			salesrefundsuccessrequestBean.setOperatorInfo("autotest");
			salesrefundsuccessrequestBean.setOrderId(orderId);
			salesrefundsuccessrequestBean.setRefundBillNo("TH0"
					+ String.valueOf(orderId));
			salesrefundsuccessrequestCall
					.setData(salesrefundsuccessrequestBean);

			Logger.comment("退该订单号" + orderId + "第一件商品");
			salesrefundsuccessrequestCall.callService();
			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");

			// 支付网关退款回调交易
			PaymentProxyCallService.refundNotifyCall(payType,
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			Thread.sleep(3000);

			DefaultWapper defaultWapper = new DefaultWapper();
			if (salesrefundsuccessrequestCall.getReturnData().equals("ok")) {
				// 数据库验
				// 查询交易退款结算表
				Map m = new HashMap();

				m.put("orderId", orderId);

				// 查询交易退款结算表
				List<YmtSettlementInvoice> settlementInvoiceList = new YmtSettlementInvoiceWapper()
						.selectYmtSettlementInvoice(m);

				settlementInvoiceList = settlementInvoiceList.stream()
						.filter(item ->

						item.getBusinessType() != 14

						).collect(Collectors.toList());

				// 订单商品表
				List<Map> orderInfoList = defaultWapper
						.selectOrderInfoByOderId(orderId);
				// 订单主表
				List<Map> ymtOrders = defaultWapper
						.selectOrderByOderId(orderId);
				// ymtOrderState 表
				List<Map> ymtOrderState = defaultWapper
						.selectOrderStateByOderId(orderId);
				YmtRefundWapper ymtRefund = new YmtRefundWapper();
				// m.put("refundBillNo", refundBillNo);
				for (int i = 0; i < orderInfoList.size(); i++) {
					// 订单退货记录
					YmtRefundBill refundBill = ymtRefund.selectRefundBill(m)
							.get(i);
					// 退货的商品记录
					YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(
							m).get(i);
					// 退款退货商品 catalogid
					String catalogId = refundPro.getCatalogId();
					/*
					 * // 商品使用的平台优惠券 BigDecimal productYmtCouponValue =
					 * BigDecimal.ZERO; for (Map m1 : orderInfoList) { if
					 * (((String) m1.get("sCatalogId")).equals(catalogId)) {
					 * productYmtCouponValue = (BigDecimal)
					 * m1.get("fYmtCouponAmount"); } }
					 */
					Logger.comment("校验订单号" + orderId + "第" + (i + 1) + "件商品");
					Logger.comment("校验Ymt_RefundBill表");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals("TH" + i + String.valueOf(orderId),
							refundBill.getRefundBillNo(), "验证RefundBillNo");
					Logger.verifyEquals(1, refundBill.getRefundStatus(),
							"验证RefundStatus");
					Logger.verifyEquals(1, refundBill.getSettlementStatus(),
							"验证SettlementStatus");
					Logger.verifyEquals(10, refundBill.getSalesRefundStatus(),
							"验证SalesRefundStatus");
					Logger.verifyEquals(1, refundBill.getRefundType(),
							"验证RefundType");
					Logger.verifyEquals("autotest refund",
							refundBill.getReason(), "验证Reason");
					// 退的平台优惠券
					/*
					 * Logger.verifyEquals(productYmtCouponValue,
					 * refundBill.getSettlementAmountOfCoupon(),
					 * "验证SettlementAmountOfCoupon");
					 */
					Logger.verifyEquals(sellerId, refundBill.getSellerId(),
							"验证SellerId");
					Logger.verifyEquals(userId, refundBill.getBuyerId(),
							"验证BuyerId");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.comment("校验Ymt_RefundProduct表");
					Logger.verifyEquals(orderId, refundPro.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals("TH" + i + String.valueOf(orderId),
							refundPro.getRefundBillNo(), "验证RefundBillNo");
					if (settlementInvoiceList.get(i).getBusinessNo()
							.equals(refundPro.getRefundBillNo())) {
						Logger.comment("校验Ymt_SettlementInvoice表");

						Logger.verifyEquals("TH" + i + String.valueOf(orderId),
								settlementInvoiceList.get(i).getBusinessNo(),
								"验证BusinessNo");
						Logger.verifyEquals(2, settlementInvoiceList.get(i)
								.getBusinessType(), "验证BusinessType");
						Logger.verifyEquals(orderId,
								settlementInvoiceList.get(i).getOrderId(),
								"验证OrderId");
						Logger.verifyEquals(
								(settlementInvoiceList.get(i).getCashAmount())
										.add(settlementInvoiceList.get(i)
												.getCouponAmount())
										.add(settlementInvoiceList.get(i)
												.getThirdPartyDiscountAmount()),
								settlementInvoiceList.get(i).getTotalAmount(),
								"验证TotalAmount");
						Logger.verifyEquals(refundBill.getRefundAmount(),
								settlementInvoiceList.get(i).getCashAmount(),
								"验证CashAmount");

						Logger.verifyEquals(sellerId, settlementInvoiceList
								.get(i).getSellerId(), "验证SellerId");
						Logger.verifyEquals("退款结算", settlementInvoiceList
								.get(i).getRemark(), "验证Remark");
						Logger.verifyEquals(1, settlementInvoiceList.get(i)
								.getSettlementStatus(), "验证SettlementStatus");
						Logger.verifyEquals(1, settlementInvoiceList.get(i)
								.getSettlementUser(), "验证SettlementUser");
						Logger.verifyEquals(null, settlementInvoiceList.get(i)
								.getProcessResult(), "验证ProcessResult");

						Logger.verifyEquals(refundBill
								.getRefundedDiscountOfThirdParty(),
								settlementInvoiceList.get(i)
										.getThirdPartyDiscountAmount(),
								"验证ThirdPartyDiscountAmount");

						Logger.comment("校验ymt_orderinfo表");
						Logger.verifyEquals(10, (Integer) orderInfoList.get(i)
								.get("iProductRefundStatus"),
								"验证iProductRefundStatus");
						// 资金流水表
						List<YmtAccountEntry> ymtActList = new AccountDefaultWapper()
								.selectAccountEntryByOriginalNo(settlementInvoiceList
										.get(i).getBusinessNo());
						List<YmtAccountEntry> userActList = ymtActList.stream()
								.filter(act -> act.getUserid() == userId)
								.collect(Collectors.toList());
						Logger.verifyEquals((settlementInvoiceList.get(i)
								.getfAccountAmount())
								.compareTo(BigDecimal.ZERO) > 0 ? 1 : 0,
								userActList.size(), "验证用户账户流水表记录");
						List<YmtAccountEntry> sellerActList = ymtActList
								.stream()
								.filter(act -> act.getUserid() == sellerId)
								.collect(Collectors.toList());
						Logger.verifyEquals(0, sellerActList.size(),
								"验证商家账户流水表记录");
					}
				}
				Logger.comment("校验ymt_orders表");
				Logger.verifyEquals(3,
						(Integer) ymtOrders.get(0).get("iTradingStatus"),
						"验证iTradingStatus");
				Logger.verifyEquals(null,
						ymtOrders.get(0).get("iSalesRefundStatus"),
						"验证iSalesRefundStatus");
				Logger.comment("校验ymt_orderstate表");
				Logger.verifyEquals(
						settlementInvoiceList.stream()
								.map(account -> account.getCashAmount())
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountOfCash"),
						"验证fRefundedAmountOfCash");
				Logger.verifyEquals(null,
						ymtOrderState.get(0).get("fRefundedAmountToAccount"),
						"验证fRefundedAmountToAccount");
				Logger.verifyEquals(
						settlementInvoiceList.stream()
								.map(account -> account.getfThirdPartyAmount())
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedPaidAmountToThirdParty"),
						"验证fRefundedPaidAmountToThirdParty");

			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SalesRefundSuccessRequest_022() {
		Logger.start(true, "全部第三方宝付支付。确认收货后,订单多个商品依次全部全款退款");
		try {
			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder4();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			OrderCallService orderCallService = new OrderCallService();

			// 用余额支付金额
			BigDecimal blanceAmout = BigDecimal.ZERO;
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "13";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, "70");
			// 支付网关支付回调交易
			PaymentProxyCallService.notifyCall("70",
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			// 等待支付网关异步处理
			Thread.sleep(5000);
			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 卖家发货
			orderCallService.dispatched(orderId, sellerId);
			// 用户确认收货
			orderCallService.confirmReceive(userId, orderId);
			Thread.sleep(3000);
			// 对结算单进行结算
			settlesellerIncome(orderId);
			// 申请退款
			applyRefundAllProduct(orderId);
			salesrefundsuccessrequestBean.setOperatorInfo("autotest");
			salesrefundsuccessrequestBean.setOrderId(orderId);
			salesrefundsuccessrequestBean.setRefundBillNo("TH0"
					+ String.valueOf(orderId));
			salesrefundsuccessrequestCall
					.setData(salesrefundsuccessrequestBean);
			Logger.comment("退该订单号" + orderId + "第一件商品");
			salesrefundsuccessrequestCall.callService();
			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");
			salesrefundsuccessrequestBean.setOrderId(orderId);
			salesrefundsuccessrequestBean.setRefundBillNo("TH1"
					+ String.valueOf(orderId));
			salesrefundsuccessrequestCall
					.setData(salesrefundsuccessrequestBean);
			Logger.comment("退该订单号" + orderId + "第二件商品");
			salesrefundsuccessrequestCall.callService();
			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");

			// 支付网关退款回调交易
			PaymentProxyCallService.refundNotifyCall("70",
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			Thread.sleep(5000);
			DefaultWapper defaultWapper = new DefaultWapper();
			if (salesrefundsuccessrequestCall.getReturnData().equals("ok")) {
				// 数据库验
				// 查询交易退款结算表
				List<Map> settlementInvoiceList = defaultWapper
						.selectYmtSettlementInvoice(orderId);
				// 订单商品表
				List<Map> orderInfoList = defaultWapper
						.selectOrderInfoByOderId(orderId);
				// 订单主表
				List<Map> ymtOrders = defaultWapper
						.selectOrderByOderId(orderId);
				// ymtOrderState 表
				List<Map> ymtOrderState = defaultWapper
						.selectOrderStateByOderId(orderId);
				YmtRefundWapper ymtRefund = new YmtRefundWapper();
				Map m = new HashMap();
				m.put("orderId", orderId);
				for (int i = 0; i < orderInfoList.size(); i++) {
					// 订单退货记录
					YmtRefundBill refundBill = ymtRefund.selectRefundBill(m)
							.get(i);
					// 退货的商品记录
					YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(
							m).get(i);
					// 退款退货商品 catalogid
					String catalogId = refundPro.getCatalogId();
					// 商品使用的平台优惠券
					BigDecimal productYmtCouponValue = BigDecimal.ZERO;
					for (Map m1 : orderInfoList) {
						if (((String) m1.get("sCatalogId")).equals(catalogId)) {
							productYmtCouponValue = (BigDecimal) m1
									.get("fYmtCouponAmount");
						}
					}
					Logger.comment("校验订单号" + orderId + "第" + (i + 1) + "件商品");
					Logger.comment("校验Ymt_RefundBill表");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals("TH" + i + String.valueOf(orderId),
							refundBill.getRefundBillNo(), "验证RefundBillNo");
					Logger.verifyEquals(1, refundBill.getRefundStatus(),
							"验证RefundStatus");
					Logger.verifyEquals(1, refundBill.getSettlementStatus(),
							"验证SettlementStatus");
					Logger.verifyEquals(10, refundBill.getSalesRefundStatus(),
							"验证SalesRefundStatus");
					Logger.verifyEquals(1, refundBill.getRefundType(),
							"验证RefundType");
					Logger.verifyEquals("autotest refund",
							refundBill.getReason(), "验证Reason");
					// 退的平台优惠券
					Logger.verifyEquals(productYmtCouponValue,
							refundBill.getSettlementAmountOfCoupon(),
							"验证SettlementAmountOfCoupon");
					Logger.verifyEquals(sellerId, refundBill.getSellerId(),
							"验证SellerId");
					Logger.verifyEquals(userId, refundBill.getBuyerId(),
							"验证BuyerId");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.comment("校验Ymt_RefundProduct表");
					Logger.verifyEquals(orderId, refundPro.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals("TH" + i + String.valueOf(orderId),
							refundPro.getRefundBillNo(), "验证RefundBillNo");
					if (settlementInvoiceList.get(i).get("BusinessNo")
							.equals(refundPro.getRefundBillNo())) {
						Logger.comment("校验Ymt_SettlementInvoice表");
						Logger.verifyEquals(
								"TH" + i + String.valueOf(orderId),
								(String) settlementInvoiceList.get(i).get(
										"BusinessNo"), "验证BusinessNo");
						Logger.verifyEquals(2, (Integer) settlementInvoiceList
								.get(i).get("BusinessType"), "验证BusinessType");
						Logger.verifyEquals(
								orderId,
								(Integer) settlementInvoiceList.get(i).get(
										"OrderId"), "验证OrderId");
						Logger.verifyEquals(
								((BigDecimal) settlementInvoiceList.get(i).get(
										"CashAmount"))
										.add((BigDecimal) settlementInvoiceList
												.get(i).get("CouponAmount")),
								(BigDecimal) settlementInvoiceList.get(i).get(
										"TotalAmount"), "验证TotalAmount");
						Logger.verifyEquals(
								refundBill.getRefundAmount(),
								(BigDecimal) settlementInvoiceList.get(i).get(
										"CashAmount"), "验证CashAmount");
						// 退的ymt 平台优惠券
						Logger.verifyEquals(
								productYmtCouponValue,
								(BigDecimal) settlementInvoiceList.get(i).get(
										"CouponAmount"), "验证CouponAmount");
						Logger.verifyEquals(
								sellerId,
								(Integer) settlementInvoiceList.get(i).get(
										"SellerId"), "验证SellerId");
						Logger.verifyEquals(
								"退款结算",
								(String) settlementInvoiceList.get(i).get(
										"Remark"), "验证Remark");
						Logger.verifyEquals(1, (Integer) settlementInvoiceList
								.get(i).get("SettlementStatus"),
								"验证SettlementStatus");
						Logger.verifyEquals(2, (Integer) settlementInvoiceList
								.get(i).get("SettlementUser"),
								"验证SettlementUser");
						Logger.verifyEquals(
								null,
								(String) settlementInvoiceList.get(i).get(
										"ProcessResult"), "验证ProcessResult");
						// 资金流水表
						List<YmtAccountEntry> ymtActList = new AccountDefaultWapper()
								.selectAccountEntryByOriginalNo((String) settlementInvoiceList
										.get(i).get("BusinessNo"));
						List<YmtAccountEntry> userActList = ymtActList.stream()
								.filter(act -> act.getUserid() == userId)
								.collect(Collectors.toList());
						Logger.verifyEquals(((BigDecimal) settlementInvoiceList
								.get(i).get("fAccountAmount"))
								.compareTo(BigDecimal.ZERO) > 0 ? 1 : 0,
								userActList.size(), "验证用户账户流水表记录");
						if (userActList.size() > 0) {
							Logger.comment("校验Ymt_AccountEntry表");
							Logger.verifyEquals(
									(BigDecimal) settlementInvoiceList.get(i)
											.get("fAccountAmount"), userActList
											.get(0).getAmount(),
									"验证用户账户流水表Amount");
						}
						List<YmtAccountEntry> sellerActList = ymtActList
								.stream()
								.filter(act -> act.getUserid() == sellerId)
								.collect(Collectors.toList());
						Logger.verifyEquals(1, sellerActList.size(),
								"验证商家账户流水表记录");
						if (sellerActList.size() > 0) {
							Logger.comment("校验Ymt_AccountEntry表");
							Logger.verifyEquals(
									(BigDecimal) settlementInvoiceList.get(i)
											.get("TotalAmount"),
									sellerActList.get(0).getAmount()
											.multiply(new BigDecimal(-1)),
									"验证商家账户流水表Amount");
						}
					}
					Logger.comment("校验ymt_orderinfo表");
					Logger.verifyEquals(
							10,
							(Integer) orderInfoList.get(i).get(
									"iProductRefundStatus"),
							"验证iProductRefundStatus");

				}
				Logger.comment("校验ymt_orderstate表");
				Logger.verifyEquals(
						settlementInvoiceList
								.stream()
								.filter(account -> (Integer) account
										.get("BusinessType") == 2)
								.map(account -> (BigDecimal) account
										.get("CashAmount"))
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountOfCash"),
						"验证fRefundedAmountOfCash");
				Logger.verifyEquals(
						settlementInvoiceList
								.stream()
								.filter(account -> (Integer) account
										.get("BusinessType") == 2)
								.map(account -> (BigDecimal) account
										.get("fAccountAmount"))
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountToAccount"),
						"验证fRefundedAmountToAccount");
				Logger.verifyEquals(
						settlementInvoiceList
								.stream()
								.filter(account -> (Integer) account
										.get("BusinessType") == 2)
								.map(account -> (BigDecimal) account
										.get("CouponAmount"))
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountOfCoupon"),
						"验证fRefundedAmountOfCoupon");
				Logger.verifyEquals(
						settlementInvoiceList
								.stream()
								.filter(account -> (Integer) account
										.get("BusinessType") == 2)
								.map(account -> (BigDecimal) account
										.get("fThirdPartyAmount"))
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedPaidAmountToThirdParty"),
						"验证fRefundedPaidAmountToThirdParty");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SalesRefundSuccessRequest_023() {
		Logger.start(true, "余额全款支付。确认收货前,订单极速退款");
		try {

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder9();;

			Order order = placeOrderResp.getOrderList().get(0);

			int orderId = order.getOrderId();
			int sellerId = order.getSellerId();

			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal amount = placeOrderResp.getPayAmount();// 支付金额

			OrderCallService orderCallService = new OrderCallService();

			for (OrderInfoPo orderInfoPo : order.getOrderInfoList()) {

				String proId = orderInfoPo.getProductId();
				String calId = orderInfoPo.getCatalogId();

				int stockNum = Ts_PlaceOrder.getStockNum(proId, calId, false);

				Logger.comment(String.format(
						"proId：%s,calalogId:%s 下单之后的库存:%s", proId, calId,
						stockNum));
			}

			// 付款
			orderCallService.orderPayRequest(userId, amount, tradingId);
			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 申请退款
			applyRefundAllProduct(orderId);
			salesrefundsuccessrequestBean.setOperatorInfo("autotest");
			salesrefundsuccessrequestBean.setOrderId(orderId);

			salesrefundsuccessrequestBean.setRefundBillNo("TH0"
					+ String.valueOf(orderId));
			salesrefundsuccessrequestBean.setTopspeedRefund(true);

			salesrefundsuccessrequestCall
					.setData(salesrefundsuccessrequestBean);
			Logger.comment("退该订单号" + orderId + "第一件商品");
			salesrefundsuccessrequestCall.callService();

			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");

			DefaultWapper defaultWapper = new DefaultWapper();

			if (salesrefundsuccessrequestCall.getReturnData().equals("ok")) {
				// 数据库验
				Map m = new HashMap();

				m.put("orderId", orderId);

				// 查询交易退款结算表
				List<YmtSettlementInvoice> settlementInvoiceList = new YmtSettlementInvoiceWapper()
						.selectYmtSettlementInvoice(m);

				settlementInvoiceList = settlementInvoiceList.stream()
						.filter(item ->

						item.getBusinessType() != 14

						).collect(Collectors.toList());

				// 订单商品表
				List<Map> orderInfoList = defaultWapper
						.selectOrderInfoByOderId(orderId);
				// 订单主表
				List<Map> ymtOrders = defaultWapper
						.selectOrderByOderId(orderId);
				// ymtOrderState 表
				List<Map> ymtOrderState = defaultWapper
						.selectOrderStateByOderId(orderId);

				YmtRefundWapper ymtRefund = new YmtRefundWapper();

				for (int i = 0; i < orderInfoList.size(); i++) {
					// 订单退货记录
					YmtRefundBill refundBill = ymtRefund.selectRefundBill(m)
							.get(i);
					// 退货的商品记录
					YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(
							m).get(i);
					// 退款退货商品 catalogid
					String catalogId = refundPro.getCatalogId();
					// 商品使用的平台优惠券
					BigDecimal productYmtCouponValue = BigDecimal.ZERO;
					for (Map m1 : orderInfoList) {
						if (((String) m1.get("sCatalogId")).equals(catalogId)) {
							productYmtCouponValue = (BigDecimal) m1
									.get("fYmtCouponAmount");
						}
					}
					Logger.comment("校验订单号" + orderId + "第" + (i + 1) + "件商品");
					Logger.comment("校验Ymt_RefundBill表");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals("TH" + i + String.valueOf(orderId),
							refundBill.getRefundBillNo(), "验证RefundBillNo");
					Logger.verifyEquals(1, refundBill.getRefundStatus(),
							"验证RefundStatus");
					Logger.verifyEquals(1, refundBill.getSettlementStatus(),
							"验证SettlementStatus");
					Logger.verifyEquals(10, refundBill.getSalesRefundStatus(),
							"验证SalesRefundStatus");
					Logger.verifyEquals(1, refundBill.getRefundType(),
							"验证RefundType");
					Logger.verifyEquals("autotest refund",
							refundBill.getReason(), "验证Reason");
					// 退的平台优惠券
					Logger.verifyEquals(productYmtCouponValue,
							refundBill.getSettlementAmountOfCoupon(),
							"验证SettlementAmountOfCoupon");
					Logger.verifyEquals(sellerId, refundBill.getSellerId(),
							"验证SellerId");
					Logger.verifyEquals(userId, refundBill.getBuyerId(),
							"验证BuyerId");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.comment("校验Ymt_RefundProduct表");
					Logger.verifyEquals(orderId, refundPro.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals("TH" + i + String.valueOf(orderId),
							refundPro.getRefundBillNo(), "验证RefundBillNo");

					if (settlementInvoiceList.get(i).getBusinessNo()
							.equals(refundPro.getRefundBillNo())) {

						Logger.comment("校验Ymt_SettlementInvoice表");

						Logger.verifyEquals("TH" + i + String.valueOf(orderId),
								settlementInvoiceList.get(i).getBusinessNo(),
								"验证BusinessNo");

						Logger.verifyEquals(2, settlementInvoiceList.get(i)
								.getBusinessType(), "验证BusinessType");

						Logger.verifyEquals(orderId,
								settlementInvoiceList.get(i).getOrderId(),
								"验证OrderId");

						Logger.verifyEquals((settlementInvoiceList.get(i)
								.getCashAmount()).add(settlementInvoiceList
								.get(i).getCouponAmount()),
								settlementInvoiceList.get(i).getTotalAmount(),
								"验证TotalAmount");

						Logger.verifyEquals(refundBill.getRefundAmount(),
								settlementInvoiceList.get(i).getCashAmount(),
								"验证CashAmount");
						// 退的ymt 平台优惠券
						Logger.verifyEquals(productYmtCouponValue,
								settlementInvoiceList.get(i).getCouponAmount(),
								"验证CouponAmount");

						Logger.verifyEquals(sellerId, settlementInvoiceList
								.get(i).getSellerId(), "验证SellerId");
						Logger.verifyEquals("退款结算", settlementInvoiceList
								.get(i).getRemark(), "验证Remark");
						Logger.verifyEquals(1, settlementInvoiceList.get(i)
								.getSettlementStatus(), "验证SettlementStatus");
						Logger.verifyEquals(1, settlementInvoiceList.get(i)
								.getSettlementUser(), "验证SettlementUser");
						Logger.verifyEquals(null, settlementInvoiceList.get(i)
								.getProcessResult(), "验证ProcessResult");
						Logger.verifyEquals(refundBill.getRefundAmount(),
								settlementInvoiceList.get(i)
										.getfAccountAmount(),
								"验证fAccountAmount");
						Logger.verifyEquals(BigDecimal.ZERO.setScale(2),
								settlementInvoiceList.get(i)
										.getfThirdPartyAmount(),
								"验证fThirdPartyAmount");
						Logger.comment("校验ymt_orderinfo表");
						Logger.verifyEquals(10, (Integer) orderInfoList.get(i)
								.get("iProductRefundStatus"),
								"验证iProductRefundStatus");
						// 资金流水表
						List<YmtAccountEntry> ymtActList = new AccountDefaultWapper()
								.selectAccountEntryByOriginalNo(settlementInvoiceList
										.get(i).getBusinessNo());
						List<YmtAccountEntry> userActList = ymtActList.stream()
								.filter(act -> act.getUserid() == userId)
								.collect(Collectors.toList());

						Logger.verifyEquals((settlementInvoiceList.get(i)
								.getfAccountAmount())
								.compareTo(BigDecimal.ZERO) > 0 ? 1 : 0,
								userActList.size(), "验证用户账户流水表记录");
						if (userActList.size() > 0) {
							Logger.comment("校验Ymt_AccountEntry表");
							Logger.verifyEquals(settlementInvoiceList.get(i)
									.getfAccountAmount(), userActList.get(0)
									.getAmount(), "验证用户账户流水表Amount");
						}
						List<YmtAccountEntry> sellerActList = ymtActList
								.stream()
								.filter(act -> act.getUserid() == sellerId)
								.collect(Collectors.toList());
						Logger.verifyEquals(0, sellerActList.size(),
								"验证商家账户流水表记录");
					}
				}
				Logger.comment("校验ymt_orders表");
				Logger.verifyEquals(12,
						(Integer) ymtOrders.get(0).get("iTradingStatus"),
						"验证iTradingStatus");
				Logger.verifyEquals(null,
						ymtOrders.get(0).get("iSalesRefundStatus"),
						"验证iSalesRefundStatus");

				Logger.comment("校验ymt_orderstate表");
				Logger.verifyEquals(
						settlementInvoiceList.stream()
								.map(account -> account.getCashAmount())
								.reduce(BigDecimal.ZERO, BigDecimal::add),

						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountOfCash"),
						"验证fRefundedAmountOfCash");
				Logger.verifyEquals(
						settlementInvoiceList.stream()
								.map(account -> account.getfAccountAmount())
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountToAccount"),
						"验证fRefundedAmountToAccount");
				Logger.verifyEquals(null, (BigDecimal) ymtOrderState.get(0)
						.get("fRefundedPaidAmountToThirdParty"),
						"验证fRefundedPaidAmountToThirdParty");

				for (OrderInfoPo orderInfoPo : order.getOrderInfoList()) {

					String proId = orderInfoPo.getProductId();
					String calId = orderInfoPo.getCatalogId();

					int stockNum = Ts_PlaceOrder.getStockNum(proId, calId,
							false);

					Logger.comment(String.format(
							"proId：%s,calalogId:%s 退货退款之后发送返库存之后的库存:%s", proId,
							calId, stockNum));
				}

			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SalesRefundSuccessRequest_024() {
		Logger.start(true, "全部第三方支付宝支付。确认收货前,订单极速退款");
		try {

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder4();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			OrderCallService orderCallService = new OrderCallService();

			// 用余额支付金额
			BigDecimal blanceAmout = BigDecimal.ZERO;
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "13";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payType);
			// 支付网关支付回调交易
			PaymentProxyCallService.notifyCall(payType,
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			// 等待支付网关异步处理
			Thread.sleep(5000);
			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 申请退款
			applyRefundAllProduct(orderId);
			salesrefundsuccessrequestBean.setOperatorInfo("autotest");
			salesrefundsuccessrequestBean.setOrderId(orderId);
			salesrefundsuccessrequestBean.setRefundBillNo("TH0"
					+ String.valueOf(orderId));

			salesrefundsuccessrequestBean.setTopspeedRefund(true);

			salesrefundsuccessrequestCall
					.setData(salesrefundsuccessrequestBean);
			Logger.comment("退该订单号" + orderId + "第一件商品");
			salesrefundsuccessrequestCall.callService();
			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");
			salesrefundsuccessrequestBean.setOrderId(orderId);
			salesrefundsuccessrequestBean.setRefundBillNo("TH1"
					+ String.valueOf(orderId));
			salesrefundsuccessrequestCall
					.setData(salesrefundsuccessrequestBean);
			Logger.comment("退该订单号" + orderId + "第二件商品");
			salesrefundsuccessrequestCall.callService();
			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");
			// 支付网关退款回调交易
			PaymentProxyCallService.refundNotifyCall(payType,
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			Thread.sleep(5000);

			DefaultWapper defaultWapper = new DefaultWapper();
			if (salesrefundsuccessrequestCall.getReturnData().equals("ok")) {

				// 数据库验
				// 查询交易退款结算表
				Map m = new HashMap();

				m.put("orderId", orderId);

				// 查询交易退款结算表
				List<YmtSettlementInvoice> settlementInvoiceList = new YmtSettlementInvoiceWapper()
						.selectYmtSettlementInvoice(m);

				settlementInvoiceList = settlementInvoiceList.stream()
						.filter(item ->

						item.getBusinessType() != 14

						).collect(Collectors.toList());
				// 订单商品表
				List<Map> orderInfoList = defaultWapper
						.selectOrderInfoByOderId(orderId);
				// 订单主表
				List<Map> ymtOrders = defaultWapper
						.selectOrderByOderId(orderId);
				// ymtOrderState 表
				List<Map> ymtOrderState = defaultWapper
						.selectOrderStateByOderId(orderId);
				YmtRefundWapper ymtRefund = new YmtRefundWapper();

				// m.put("refundBillNo", refundBillNo);
				for (int i = 0; i < orderInfoList.size(); i++) {
					// 订单退货记录
					YmtRefundBill refundBill = ymtRefund.selectRefundBill(m)
							.get(i);
					// 退货的商品记录
					YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(
							m).get(i);
					// 退款退货商品 catalogid
					String catalogId = refundPro.getCatalogId();
					// 商品使用的平台优惠券
					BigDecimal productYmtCouponValue = BigDecimal.ZERO;
					for (Map m1 : orderInfoList) {
						if (((String) m1.get("sCatalogId")).equals(catalogId)) {
							productYmtCouponValue = (BigDecimal) m1
									.get("fYmtCouponAmount");
						}
					}
					Logger.comment("校验订单号" + orderId + "第" + (i + 1) + "件商品");
					Logger.comment("校验Ymt_RefundBill表");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals("TH" + i + String.valueOf(orderId),
							refundBill.getRefundBillNo(), "验证RefundBillNo");
					Logger.verifyEquals(1, refundBill.getRefundStatus(),
							"验证RefundStatus");
					Logger.verifyEquals(1, refundBill.getSettlementStatus(),
							"验证SettlementStatus");
					Logger.verifyEquals(10, refundBill.getSalesRefundStatus(),
							"验证SalesRefundStatus");
					Logger.verifyEquals(1, refundBill.getRefundType(),
							"验证RefundType");
					Logger.verifyEquals("autotest refund",
							refundBill.getReason(), "验证Reason");
					// 退的平台优惠券
					Logger.verifyEquals(productYmtCouponValue,
							refundBill.getSettlementAmountOfCoupon(),
							"验证SettlementAmountOfCoupon");
					Logger.verifyEquals(sellerId, refundBill.getSellerId(),
							"验证SellerId");
					Logger.verifyEquals(userId, refundBill.getBuyerId(),
							"验证BuyerId");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.comment("校验Ymt_RefundProduct表");
					Logger.verifyEquals(orderId, refundPro.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals("TH" + i + String.valueOf(orderId),
							refundPro.getRefundBillNo(), "验证RefundBillNo");
					if (settlementInvoiceList.get(i).getBusinessNo()
							.equals(refundPro.getRefundBillNo())) {
						Logger.comment("校验Ymt_SettlementInvoice表");

						Logger.verifyEquals("TH" + i + String.valueOf(orderId),
								settlementInvoiceList.get(i).getBusinessNo(),
								"验证BusinessNo");
						Logger.verifyEquals(2, settlementInvoiceList.get(i)
								.getBusinessType(), "验证BusinessType");
						Logger.verifyEquals(orderId,
								settlementInvoiceList.get(i).getOrderId(),
								"验证OrderId");
						Logger.verifyEquals((settlementInvoiceList.get(i)
								.getCashAmount()).add(settlementInvoiceList
								.get(i).getCouponAmount()),
								settlementInvoiceList.get(i).getTotalAmount(),
								"验证TotalAmount");
						Logger.verifyEquals(refundBill.getRefundAmount(),
								settlementInvoiceList.get(i).getCashAmount(),
								"验证CashAmount");
						// 退的ymt 平台优惠券
						Logger.verifyEquals(productYmtCouponValue,
								settlementInvoiceList.get(i).getCouponAmount(),
								"验证CouponAmount");
						Logger.verifyEquals(sellerId, settlementInvoiceList
								.get(i).getSellerId(), "验证SellerId");
						Logger.verifyEquals("退款结算", settlementInvoiceList
								.get(i).getRemark(), "验证Remark");
						Logger.verifyEquals(1, settlementInvoiceList.get(i)
								.getSettlementStatus(), "验证SettlementStatus");
						Logger.verifyEquals(1, settlementInvoiceList.get(i)
								.getSettlementUser(), "验证SettlementUser");
						Logger.verifyEquals(null, settlementInvoiceList.get(i)
								.getProcessResult(), "验证ProcessResult");
						Logger.comment("校验ymt_orderinfo表");
						Logger.verifyEquals(10, (Integer) orderInfoList.get(i)
								.get("iProductRefundStatus"),
								"验证iProductRefundStatus");
						// 资金流水表
						List<YmtAccountEntry> ymtActList = new AccountDefaultWapper()
								.selectAccountEntryByOriginalNo(settlementInvoiceList
										.get(i).getBusinessNo());
						List<YmtAccountEntry> userActList = ymtActList.stream()
								.filter(act -> act.getUserid() == userId)
								.collect(Collectors.toList());
						Logger.verifyEquals(((BigDecimal) settlementInvoiceList
								.get(i).getfAccountAmount())
								.compareTo(BigDecimal.ZERO) > 0 ? 1 : 0,
								userActList.size(), "验证用户账户流水表记录");
						List<YmtAccountEntry> sellerActList = ymtActList
								.stream()
								.filter(act -> act.getUserid() == sellerId)
								.collect(Collectors.toList());
						Logger.verifyEquals(0, sellerActList.size(),
								"验证商家账户流水表记录");
					}
				}
				Logger.comment("校验ymt_orders表");
				Logger.verifyEquals(12,
						(Integer) ymtOrders.get(0).get("iTradingStatus"),
						"验证iTradingStatus");
				Logger.verifyEquals(null,
						ymtOrders.get(0).get("iSalesRefundStatus"),
						"验证iSalesRefundStatus");
				Logger.comment("校验ymt_orderstate表");
				Logger.verifyEquals(
						settlementInvoiceList.stream()
								.map(account -> account.getCashAmount())
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountOfCash"),
						"验证fRefundedAmountOfCash");
				Logger.verifyEquals(null,
						ymtOrderState.get(0).get("fRefundedAmountToAccount"),
						"验证fRefundedAmountToAccount");

				Logger.verifyEquals(

						settlementInvoiceList.stream()

						.map(account -> account.getfThirdPartyAmount())
								.reduce(BigDecimal.ZERO, BigDecimal::add),

						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedPaidAmountToThirdParty"),
						"验证fRefundedPaidAmountToThirdParty");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SalesRefundSuccessRequest_025() {
		Logger.start(true, "确认收货后,商家备用金不够,极速退款,正常退款给买家");
		try {

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder4();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			OrderCallService orderCallService = new OrderCallService();

			// 用余额支付金额
			BigDecimal blanceAmout = BigDecimal.ZERO;
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "13";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payType);
			// 支付网关支付回调交易
			PaymentProxyCallService.notifyCall(payType,
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			// 等待支付网关异步处理
			Thread.sleep(5000);

			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 发货
			orderCallService.dispatched(orderId, sellerId);
			// 确认收货
			orderCallService.confirmReceive(userId, orderId);

			Thread.sleep(3000);
			// 对结算单进行结算
			settlesellerIncome(orderId);
			// 申请退款
			applyRefundAllProduct(orderId);
			String refundBillNo = "TH0" + String.valueOf(orderId);
			// 重置商家余额
			AccountCallServiceV2 AccountCallServiceV2 = new AccountCallServiceV2();
			String accountid = AccountCallServiceV2.getAccountId(sellerId);
			AccountCallServiceV2.resetAccount(accountid, new BigDecimal(10),
					BigDecimal.ZERO);

			salesrefundsuccessrequestBean.setOperatorInfo("autotest");
			salesrefundsuccessrequestBean.setOrderId(orderId);
			salesrefundsuccessrequestBean.setRefundBillNo(refundBillNo);
			salesrefundsuccessrequestBean.setTopspeedRefund(true);

			salesrefundsuccessrequestCall
					.setData(salesrefundsuccessrequestBean);
			salesrefundsuccessrequestCall.callService();
			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");

			// 支付网关退款回调交易
			PaymentProxyCallService.refundNotifyCall(payType,
					String.valueOf(thirdTradingId),
					totalPrice.subtract(blanceAmout).toString(), userId);
			Thread.sleep(5000);

			DefaultWapper defaultWapper = new DefaultWapper();
			// 数据库验
			// 查询交易退款结算表
			List<Map> settlementInvoiceList = defaultWapper
					.selectYmtSettlementInvoice(orderId);
			// 订单商品表
			List<Map> orderInfoList = defaultWapper
					.selectOrderInfoByOderId(orderId);
			// 订单主表
			List<Map> ymtOrders = defaultWapper.selectOrderByOderId(orderId);
			// ymtOrderState 表
			List<Map> ymtOrderState = defaultWapper
					.selectOrderStateByOderId(orderId);
			YmtRefundWapper ymtRefund = new YmtRefundWapper();
			Map m = new HashMap();
			m.put("orderId", orderId);
			m.put("refundBillNo", refundBillNo);
			// 订单退货记录
			YmtRefundBill refundBill = ymtRefund.selectRefundBill(m).get(0);
			// 退货的商品记录
			YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(m)
					.get(0);
			// 退款退货商品 catalogid
			String catalogId = refundPro.getCatalogId();
			// 商品使用的平台优惠券
			BigDecimal productYmtCouponValue = BigDecimal.ZERO;
			for (Map m1 : orderInfoList) {
				if (((String) m1.get("sCatalogId")).equals(catalogId)) {
					productYmtCouponValue = (BigDecimal) m1
							.get("fYmtCouponAmount");
				}
			}
			Logger.comment("校验订单号" + orderId + "第1件商品");
			Logger.comment("校验Ymt_RefundBill表");
			Logger.verifyEquals(orderId, refundBill.getOrderId(), "验证OrderId");
			Logger.verifyEquals(refundBillNo, refundBill.getRefundBillNo(),
					"验证RefundBillNo");
			Logger.verifyEquals(0, refundBill.getRefundStatus(),
					"验证RefundStatus");
			Logger.verifyEquals(0, refundBill.getSettlementStatus(),
					"验证SettlementStatus");
			Logger.verifyEquals(10, refundBill.getSalesRefundStatus(),
					"验证SalesRefundStatus");
			Logger.verifyEquals(1, refundBill.getRefundType(), "验证RefundType");
			Logger.verifyEquals("autotest refund", refundBill.getReason(),
					"验证Reason");
			// 退的平台优惠券
			Logger.verifyEquals(productYmtCouponValue,
					refundBill.getSettlementAmountOfCoupon(),
					"验证SettlementAmountOfCoupon");
			Logger.verifyEquals(sellerId, refundBill.getSellerId(),
					"验证SellerId");
			Logger.verifyEquals(userId, refundBill.getBuyerId(), "验证BuyerId");
			Logger.verifyEquals(orderId, refundBill.getOrderId(), "验证OrderId");
			Logger.comment("校验Ymt_RefundProduct表");
			Logger.verifyEquals(orderId, refundPro.getOrderId(), "验证OrderId");
			Logger.verifyEquals(refundBillNo, refundPro.getRefundBillNo(),
					"验证RefundBillNo");
			List<Map> settlementInvoiceList2 = settlementInvoiceList
					.stream()
					.filter(settlement -> (Integer) settlement
							.get("BusinessType") == 2)
					.collect(Collectors.toList());
			Logger.comment("校验Ymt_SettlementInvoice表 退款结算");
			Logger.verifyEquals(refundBillNo, (String) settlementInvoiceList2
					.get(0).get("BusinessNo"), "验证BusinessNo");
			Logger.verifyEquals(
					2,
					(Integer) settlementInvoiceList2.get(0).get("BusinessType"),
					"验证BusinessType");
			Logger.verifyEquals(orderId, (Integer) settlementInvoiceList2
					.get(0).get("OrderId"), "验证OrderId");
			Logger.verifyEquals(
					((BigDecimal) settlementInvoiceList2.get(0).get(
							"CashAmount"))
							.add((BigDecimal) settlementInvoiceList2.get(0)
									.get("CouponAmount")),
					(BigDecimal) settlementInvoiceList2.get(0).get(
							"TotalAmount"), "验证TotalAmount");
			Logger.verifyEquals(refundBill.getRefundAmount(),
					(BigDecimal) settlementInvoiceList2.get(0)
							.get("CashAmount"), "验证CashAmount");
			// 确认收货的ymt 平台优惠券
			Logger.verifyEquals(
					refundBill.getSettlementAmountOfCoupon(),
					(BigDecimal) settlementInvoiceList2.get(0).get(
							"CouponAmount"), "验证CouponAmount");
			Logger.verifyEquals(sellerId,
					(Integer) settlementInvoiceList2.get(0).get("SellerId"),
					"验证SellerId");
			Logger.verifyEquals("退款结算", (String) settlementInvoiceList2.get(0)
					.get("Remark"), "验证Remark");
			Logger.verifyEquals(
					0,
					(Integer) settlementInvoiceList2.get(0).get(
							"SettlementStatus"), "验证SettlementStatus");
			Logger.verifyEquals(
					2,
					(Integer) settlementInvoiceList2.get(0).get(
							"SettlementUser"), "验证SettlementUser");
			Logger.verifyEquals(null, (String) settlementInvoiceList2.get(0)
					.get("ProcessResult"), "验证ProcessResult");
			Logger.comment("校验ymt_orderinfo表");
			Logger.verifyEquals(10,
					(Integer) orderInfoList.get(0).get("iProductRefundStatus"),
					"验证iProductRefundStatus");
			Logger.verifyEquals(1,
					(Integer) orderInfoList.get(1).get("iProductRefundStatus"),
					"验证iProductRefundStatus");
			Logger.comment("校验ymt_orders表");
			Logger.verifyEquals(4,
					(Integer) ymtOrders.get(0).get("iTradingStatus"),
					"验证iTradingStatus");
			Logger.verifyEquals(null, ymtOrders.get(0)
					.get("iSalesRefundStatus"), "验证iSalesRefundStatus");
			Logger.comment("校验ymt_orderstate表");
			Logger.verifyEquals(
					(BigDecimal) settlementInvoiceList2.get(0)
							.get("CashAmount"),
					(BigDecimal) ymtOrderState.get(0).get(
							"fRefundedAmountOfCash"), "验证fRefundedAmountOfCash");

			AccountCallServiceV2.resetAccount(accountid,
					new BigDecimal(99999999), BigDecimal.ZERO);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SalesRefundSuccessRequest_026() {
		Logger.start(true, "退款退货,校验库存返还情况");
		try {

			PlaceOrderResp placeOrderResp = PlaceOrderService.placeOrder9();;

			Order order = placeOrderResp.getOrderList().get(0);

			int orderId = order.getOrderId();
			int sellerId = order.getSellerId();

			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal amount = placeOrderResp.getPayAmount();// 支付金额

			OrderCallService orderCallService = new OrderCallService();

			for (OrderInfoPo orderInfoPo : order.getOrderInfoList()) {

				String proId = orderInfoPo.getProductId();
				String calId = orderInfoPo.getCatalogId();

				int stockNum = Ts_PlaceOrder.getStockNum(proId, calId, false);

				Logger.comment(String.format(
						"proId：%s,calalogId:%s 下单之后的库存:%s", proId, calId,
						stockNum));
			}

			// 付款
			orderCallService.orderPayRequest(userId, amount, tradingId);
			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 申请退款
			applyRefundAllProduct(orderId);
			salesrefundsuccessrequestBean.setOperatorInfo("autotest");
			salesrefundsuccessrequestBean.setOrderId(orderId);

			salesrefundsuccessrequestBean.setRefundBillNo("TH0"
					+ String.valueOf(orderId));

			salesrefundsuccessrequestCall
					.setData(salesrefundsuccessrequestBean);
			Logger.comment("退该订单号" + orderId + "第一件商品");
			salesrefundsuccessrequestCall.callService();
			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");
			salesrefundsuccessrequestBean.setOrderId(orderId);
			salesrefundsuccessrequestBean.setRefundBillNo("TH1"
					+ String.valueOf(orderId));
			salesrefundsuccessrequestCall
					.setData(salesrefundsuccessrequestBean);
			Logger.comment("退该订单号" + orderId + "第二件商品");

			// Thread.sleep(5000);
			salesrefundsuccessrequestCall.callService();

			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");
			DefaultWapper defaultWapper = new DefaultWapper();

			if (salesrefundsuccessrequestCall.getReturnData().equals("ok")) {

				// 订单商品表
				List<Map> orderInfoList = defaultWapper
						.selectOrderInfoByOderId(orderId);

				for (OrderInfoPo orderInfoPo : order.getOrderInfoList()) {

					String proId = orderInfoPo.getProductId();
					String calId = orderInfoPo.getCatalogId();

					int stockNum = Ts_PlaceOrder.getStockNum(proId, calId,
							false);

					Logger.comment(String.format(
							"proId：%s,calalogId:%s 退货退款之后发送返库存之后的库存:%s", proId,
							calId, stockNum));
				}

			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SalesRefundSuccessRequest_027() {
		Logger.start(true, "使用了预付卡订单，全余额支付。确认收货前,订单多个商品依次全部全款退款");
		try {

			PlaceOrderResp placeOrderResp = PrepaidCardService.placeOrder(true);

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			OrderCallService orderCallService = new OrderCallService();

			// 用余额支付金额
			BigDecimal blanceAmout = BigDecimal.ZERO;
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "13";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payType);

			new OrderCallService().orderPayCallBack(String
					.valueOf(thirdTradingId));

			// 等待支付网关异步处理
			Thread.sleep(2000);
			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 申请退款
			ApplySalesRefundRequestBean applySalesRefund = applyRefundAllProduct(orderId);

			salesrefundsuccessrequestBean.setOrderId(orderId);

			salesrefundsuccessrequestBean.setOperatorInfo("autotest");

			BigDecimal beforeAmount = AccountCallServiceV2.getAccountBalance(
					userId, 1);

			for (int i = 0; i < applySalesRefund.getSalesRefundInfoList()
					.size(); i++) {

				SalesRefundInfoBean salesRefundInfoBean = applySalesRefund
						.getSalesRefundInfoList().get(i);

				salesrefundsuccessrequestBean
						.setRefundBillNo(salesRefundInfoBean.getRefundBillNo());

				salesrefundsuccessrequestCall
						.setData(salesrefundsuccessrequestBean);

				Logger.comment(String.format("退该订单号 %s 第%s件商品", orderId, i + 1));
				salesrefundsuccessrequestCall.callService();

			}

			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");

			DefaultWapper defaultWapper = new DefaultWapper();
			if (salesrefundsuccessrequestCall.getReturnData().equals("ok")) {

				// 数据库验
				Map m = new HashMap();

				m.put("orderId", orderId);

				// 订单商品表
				List<Map> orderInfoList = defaultWapper
						.selectOrderInfoByOderId(orderId);
				// 订单主表
				List<Map> ymtOrders = defaultWapper
						.selectOrderByOderId(orderId);
				// ymtOrderState 表
				List<Map> ymtOrderState = defaultWapper
						.selectOrderStateByOderId(orderId);
				YmtRefundWapper ymtRefund = new YmtRefundWapper();

				// m.put("refundBillNo", refundBillNo);
				for (int i = 0; i < applySalesRefund.getSalesRefundInfoList()
						.size(); i++) {

					SalesRefundInfoBean salesRefundInfo = applySalesRefund
							.getSalesRefundInfoList().get(i);

					// 订单退货记录
					YmtRefundBill refundBill = ymtRefund.selectRefundBill(m)
							.get(i);
					// 退货的商品记录
					YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(
							m).get(i);

					Logger.comment("校验订单号" + orderId + "第" + (i + 1) + "件商品");
					Logger.comment("校验Ymt_RefundBill表");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals(salesRefundInfo.getRefundBillNo(),
							refundBill.getRefundBillNo(), "验证RefundBillNo");

					DataUtil.verifyDecimalEquals(
							salesRefundInfo.getRefundAmount(),
							refundBill.getRefundAmount(), "验证refundAmount");

					Logger.verifyEquals(1, refundBill.getRefundStatus(),
							"验证RefundStatus");
					Logger.verifyEquals(1, refundBill.getSettlementStatus(),
							"验证SettlementStatus");
					Logger.verifyEquals(10, refundBill.getSalesRefundStatus(),
							"验证SalesRefundStatus");
					Logger.verifyEquals(1, refundBill.getRefundType(),
							"验证RefundType");

					Logger.verifyEquals(sellerId, refundBill.getSellerId(),
							"验证SellerId");
					Logger.verifyEquals(userId, refundBill.getBuyerId(),
							"验证BuyerId");

					Logger.comment("校验Ymt_RefundProduct表");

					Logger.verifyEquals(orderId, refundPro.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals(salesRefundInfo.getRefundBillNo(),
							refundPro.getRefundBillNo(), "验证RefundBillNo");

					m.put("businessNo", salesRefundInfo.getRefundBillNo());

					// 查询交易退款结算表
					List<YmtSettlementInvoice> settlementInvoiceList = new YmtSettlementInvoiceWapper()
							.selectYmtSettlementInvoice(m);

					YmtSettlementInvoice refundSettlementInvoice = settlementInvoiceList
							.get(0);

					Logger.comment("校验Ymt_SettlementInvoice表");

					Logger.verifyEquals(salesRefundInfo.getRefundBillNo(),
							refundSettlementInvoice.getBusinessNo(),
							"验证BusinessNo");
					Logger.verifyEquals(2,
							refundSettlementInvoice.getBusinessType(),
							"验证BusinessType");
					Logger.verifyEquals(orderId,
							refundSettlementInvoice.getOrderId(), "验证OrderId");

					Logger.verifyEquals(
							refundBill.getRefundAmount().add(
									Utils.zeroIfNull(refundBill
											.getSettlementAmountOfCoupon())),
							refundSettlementInvoice.getTotalAmount(),
							"验证TotalAmount");

					Logger.verifyEquals(refundBill.getRefundAmount(),
							refundSettlementInvoice.getCashAmount(),
							"验证CashAmount");

					Logger.verifyEquals(sellerId,
							refundSettlementInvoice.getSellerId(), "验证SellerId");
					Logger.verifyEquals("退款结算",
							refundSettlementInvoice.getRemark(), "验证Remark");
					Logger.verifyEquals(1,
							refundSettlementInvoice.getSettlementStatus(),
							"验证SettlementStatus");
					Logger.verifyEquals(1,
							refundSettlementInvoice.getSettlementUser(),
							"验证SettlementUser");
					Logger.verifyEquals(null,
							refundSettlementInvoice.getProcessResult(),
							"验证ProcessResult");

					Logger.comment("校验ymt_orderinfo表");
					Logger.verifyEquals(
							10,
							(Integer) orderInfoList.get(i).get(
									"iProductRefundStatus"),
							"验证iProductRefundStatus");

				}

				Logger.comment("校验ymt_orders表");

				Logger.verifyEquals(12,
						(Integer) ymtOrders.get(0).get("iTradingStatus"),
						"验证iTradingStatus");
				Logger.verifyEquals(null,
						ymtOrders.get(0).get("iSalesRefundStatus"),
						"验证iSalesRefundStatus");

				m.remove("businessNo");
				m.put("businessType", 2);

				// 查询交易退款结算表
				List<YmtSettlementInvoice> settlementInvoiceList = new YmtSettlementInvoiceWapper()
						.selectYmtSettlementInvoice(m);

				Logger.comment("校验ymt_orderstate表");

				DataUtil.verifyDecimalEquals(
						settlementInvoiceList.stream()
								.map(account -> account.getCashAmount())
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountOfCash"),
						"验证fRefundedAmountOfCash");

				BigDecimal fRefundedAmountToAccount = Utils
						.zeroIfNull((BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountToAccount"));

				BigDecimal fRefundedPaidAmountToThirdParty = Utils
						.zeroIfNull((BigDecimal) ymtOrderState.get(0).get(
								"fRefundedPaidAmountToThirdParty"));

				BigDecimal fRefundedPrepaidAmount = Utils
						.zeroIfNull((BigDecimal) ymtOrderState.get(0).get(
								"fRefundedPrepaidAmount"));

				DataUtil.verifyDecimalEquals(
						fRefundedAmountToAccount.add(
								fRefundedPaidAmountToThirdParty).add(
								fRefundedPrepaidAmount),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountOfCash"),
						"验证fRefundedAmountOfCash");

				DataUtil.verifyDecimalEquals(fRefundedPrepaidAmount,
						PrepaidCardService
								.getCardEntry(userId, "TH0" + orderId),
						"校验取消订单退回的预付卡金额");

				BigDecimal afterAmount = AccountCallServiceV2
						.getAccountBalance(userId, 1);

				DataUtil.verifyDecimalEquals(fRefundedAmountToAccount,
						afterAmount.subtract(beforeAmount), "校验取消订单退回的资金账户金额");

			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SalesRefundSuccessRequest_028() {
		Logger.start(true, "使用了预付卡订单，余额+第三方支付宝组合支付。确认收货前,订单多个商品依次全部全款退款");
		try {

			PlaceOrderResp placeOrderResp = PrepaidCardService.placeOrder(true);

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			OrderCallService orderCallService = new OrderCallService();

			// 用余额支付金额
			BigDecimal blanceAmout = new BigDecimal(47);
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "13";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payType);

			new OrderCallService().orderPayCallBack(String
					.valueOf(thirdTradingId));

			// 等待支付网关异步处理
			Thread.sleep(2000);
			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 申请退款
			ApplySalesRefundRequestBean applySalesRefund = applyRefundAllProduct(orderId);

			salesrefundsuccessrequestBean.setOrderId(orderId);

			salesrefundsuccessrequestBean.setOperatorInfo("autotest");

			BigDecimal beforeAmount = AccountCallServiceV2.getAccountBalance(
					userId, 1);

			for (int i = 0; i < applySalesRefund.getSalesRefundInfoList()
					.size(); i++) {

				SalesRefundInfoBean salesRefundInfoBean = applySalesRefund
						.getSalesRefundInfoList().get(i);

				salesrefundsuccessrequestBean
						.setRefundBillNo(salesRefundInfoBean.getRefundBillNo());

				salesrefundsuccessrequestCall
						.setData(salesrefundsuccessrequestBean);

				Logger.comment(String.format("退该订单号 %s 第%s件商品", orderId, i + 1));
				salesrefundsuccessrequestCall.callService();

			}

			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");

			DefaultWapper defaultWapper = new DefaultWapper();
			if (salesrefundsuccessrequestCall.getReturnData().equals("ok")) {

				// 数据库验
				Map m = new HashMap();

				m.put("orderId", orderId);

				// 订单商品表
				List<Map> orderInfoList = defaultWapper
						.selectOrderInfoByOderId(orderId);
				// 订单主表
				List<Map> ymtOrders = defaultWapper
						.selectOrderByOderId(orderId);
				// ymtOrderState 表
				List<Map> ymtOrderState = defaultWapper
						.selectOrderStateByOderId(orderId);
				YmtRefundWapper ymtRefund = new YmtRefundWapper();

				// m.put("refundBillNo", refundBillNo);
				for (int i = 0; i < applySalesRefund.getSalesRefundInfoList()
						.size(); i++) {

					SalesRefundInfoBean salesRefundInfo = applySalesRefund
							.getSalesRefundInfoList().get(i);

					// 订单退货记录
					YmtRefundBill refundBill = ymtRefund.selectRefundBill(m)
							.get(i);
					// 退货的商品记录
					YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(
							m).get(i);

					Logger.comment("校验订单号" + orderId + "第" + (i + 1) + "件商品");
					Logger.comment("校验Ymt_RefundBill表");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals(salesRefundInfo.getRefundBillNo(),
							refundBill.getRefundBillNo(), "验证RefundBillNo");

					DataUtil.verifyDecimalEquals(
							salesRefundInfo.getRefundAmount(),
							refundBill.getRefundAmount(), "验证refundAmount");

					Logger.verifyEquals(1, refundBill.getRefundStatus(),
							"验证RefundStatus");
					Logger.verifyEquals(1, refundBill.getSettlementStatus(),
							"验证SettlementStatus");
					Logger.verifyEquals(10, refundBill.getSalesRefundStatus(),
							"验证SalesRefundStatus");
					Logger.verifyEquals(1, refundBill.getRefundType(),
							"验证RefundType");

					Logger.verifyEquals(sellerId, refundBill.getSellerId(),
							"验证SellerId");
					Logger.verifyEquals(userId, refundBill.getBuyerId(),
							"验证BuyerId");

					Logger.comment("校验Ymt_RefundProduct表");

					Logger.verifyEquals(orderId, refundPro.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals(salesRefundInfo.getRefundBillNo(),
							refundPro.getRefundBillNo(), "验证RefundBillNo");

					m.put("businessNo", salesRefundInfo.getRefundBillNo());

					// 查询交易退款结算表
					List<YmtSettlementInvoice> settlementInvoiceList = new YmtSettlementInvoiceWapper()
							.selectYmtSettlementInvoice(m);

					YmtSettlementInvoice refundSettlementInvoice = settlementInvoiceList
							.get(0);

					Logger.comment("校验Ymt_SettlementInvoice表");

					Logger.verifyEquals(salesRefundInfo.getRefundBillNo(),
							refundSettlementInvoice.getBusinessNo(),
							"验证BusinessNo");
					Logger.verifyEquals(2,
							refundSettlementInvoice.getBusinessType(),
							"验证BusinessType");
					Logger.verifyEquals(orderId,
							refundSettlementInvoice.getOrderId(), "验证OrderId");

					Logger.verifyEquals(
							refundBill.getRefundAmount().add(
									Utils.zeroIfNull(refundBill
											.getSettlementAmountOfCoupon())),
							refundSettlementInvoice.getTotalAmount(),
							"验证TotalAmount");

					Logger.verifyEquals(refundBill.getRefundAmount(),
							refundSettlementInvoice.getCashAmount(),
							"验证CashAmount");

					Logger.verifyEquals(sellerId,
							refundSettlementInvoice.getSellerId(), "验证SellerId");
					Logger.verifyEquals("退款结算",
							refundSettlementInvoice.getRemark(), "验证Remark");
					Logger.verifyEquals(1,
							refundSettlementInvoice.getSettlementStatus(),
							"验证SettlementStatus");
					Logger.verifyEquals(1,
							refundSettlementInvoice.getSettlementUser(),
							"验证SettlementUser");
					Logger.verifyEquals(null,
							refundSettlementInvoice.getProcessResult(),
							"验证ProcessResult");

					Logger.comment("校验ymt_orderinfo表");
					Logger.verifyEquals(
							10,
							(Integer) orderInfoList.get(i).get(
									"iProductRefundStatus"),
							"验证iProductRefundStatus");

				}

				Logger.comment("校验ymt_orders表");

				Logger.verifyEquals(12,
						(Integer) ymtOrders.get(0).get("iTradingStatus"),
						"验证iTradingStatus");
				Logger.verifyEquals(null,
						ymtOrders.get(0).get("iSalesRefundStatus"),
						"验证iSalesRefundStatus");

				m.remove("businessNo");
				m.put("businessType", 2);

				// 查询交易退款结算表
				List<YmtSettlementInvoice> settlementInvoiceList = new YmtSettlementInvoiceWapper()
						.selectYmtSettlementInvoice(m);

				Logger.comment("校验ymt_orderstate表");

				DataUtil.verifyDecimalEquals(
						settlementInvoiceList.stream()
								.map(account -> account.getCashAmount())
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountOfCash"),
						"验证fRefundedAmountOfCash");

				BigDecimal fRefundedAmountToAccount = Utils
						.zeroIfNull((BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountToAccount"));

				BigDecimal fRefundedPaidAmountToThirdParty = Utils
						.zeroIfNull((BigDecimal) ymtOrderState.get(0).get(
								"fRefundedPaidAmountToThirdParty"));

				BigDecimal fRefundedPrepaidAmount = Utils
						.zeroIfNull((BigDecimal) ymtOrderState.get(0).get(
								"fRefundedPrepaidAmount"));

				DataUtil.verifyDecimalEquals(
						fRefundedAmountToAccount.add(
								fRefundedPaidAmountToThirdParty).add(
								fRefundedPrepaidAmount),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountOfCash"),
						"验证fRefundedAmountOfCash");

				DataUtil.verifyDecimalEquals(fRefundedPrepaidAmount,
						PrepaidCardService
								.getCardEntry(userId, "TH0" + orderId),
						"校验取消订单退回的预付卡金额");

				BigDecimal afterAmount = AccountCallServiceV2
						.getAccountBalance(userId, 1);

				DataUtil.verifyDecimalEquals(fRefundedAmountToAccount,
						afterAmount.subtract(beforeAmount), "校验取消订单退回的资金账户金额");

			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SalesRefundSuccessRequest_029() {
		Logger.start(true, "使用了预付卡订单，余额+第三方支付宝组合支付。确认收货前,订单部分退款的金额超过余额支付的部分");
		try {

			PlaceOrderResp placeOrderResp = PrepaidCardService.placeOrder(true);

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			OrderCallService orderCallService = new OrderCallService();

			// 用余额支付金额
			BigDecimal blanceAmout = new BigDecimal(47);
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "13";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payType);

			new OrderCallService().orderPayCallBack(String
					.valueOf(thirdTradingId));

			// 等待支付网关异步处理
			Thread.sleep(2000);
			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 申请退款
			ApplySalesRefundRequestBean applySalesRefund = new OrderCallService()
					.applySalesRefundRequestInJavaBean(orderId);

			applySalesRefund.getSalesRefundInfoList().remove(1);
			applySalesRefund.getSalesRefundInfoList().get(0)
					.setRefundAmount(blanceAmout.add(BigDecimal.TEN));

			new OrderCallService()
					.applySalesRefundRequestCall(applySalesRefund);

			salesrefundsuccessrequestBean.setOrderId(orderId);

			salesrefundsuccessrequestBean.setOperatorInfo("autotest");

			BigDecimal beforeAmount = AccountCallServiceV2.getAccountBalance(
					userId, 1);

			for (int i = 0; i < applySalesRefund.getSalesRefundInfoList()
					.size(); i++) {

				SalesRefundInfoBean salesRefundInfoBean = applySalesRefund
						.getSalesRefundInfoList().get(i);

				salesrefundsuccessrequestBean
						.setRefundBillNo(salesRefundInfoBean.getRefundBillNo());

				salesrefundsuccessrequestCall
						.setData(salesrefundsuccessrequestBean);

				Logger.comment(String.format("退该订单号 %s 第%s件商品", orderId, i + 1));
				salesrefundsuccessrequestCall.callService();

			}

			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");

			DefaultWapper defaultWapper = new DefaultWapper();
			if (salesrefundsuccessrequestCall.getReturnData().equals("ok")) {

				// 数据库验
				Map m = new HashMap();

				m.put("orderId", orderId);

				// 订单商品表
				List<Map> orderInfoList = defaultWapper
						.selectOrderInfoByOderId(orderId);
				// 订单主表
				List<Map> ymtOrders = defaultWapper
						.selectOrderByOderId(orderId);
				// ymtOrderState 表
				List<Map> ymtOrderState = defaultWapper
						.selectOrderStateByOderId(orderId);
				YmtRefundWapper ymtRefund = new YmtRefundWapper();

				// m.put("refundBillNo", refundBillNo);
				for (int i = 0; i < applySalesRefund.getSalesRefundInfoList()
						.size(); i++) {

					SalesRefundInfoBean salesRefundInfo = applySalesRefund
							.getSalesRefundInfoList().get(i);

					// 订单退货记录
					YmtRefundBill refundBill = ymtRefund.selectRefundBill(m)
							.get(i);
					// 退货的商品记录
					YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(
							m).get(i);

					Logger.comment("校验订单号" + orderId + "第" + (i + 1) + "件商品");
					Logger.comment("校验Ymt_RefundBill表");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals(salesRefundInfo.getRefundBillNo(),
							refundBill.getRefundBillNo(), "验证RefundBillNo");

					DataUtil.verifyDecimalEquals(
							salesRefundInfo.getRefundAmount(),
							refundBill.getRefundAmount(), "验证refundAmount");

					Logger.verifyEquals(1, refundBill.getRefundStatus(),
							"验证RefundStatus");
					Logger.verifyEquals(1, refundBill.getSettlementStatus(),
							"验证SettlementStatus");
					Logger.verifyEquals(10, refundBill.getSalesRefundStatus(),
							"验证SalesRefundStatus");
					Logger.verifyEquals(1, refundBill.getRefundType(),
							"验证RefundType");

					Logger.verifyEquals(sellerId, refundBill.getSellerId(),
							"验证SellerId");
					Logger.verifyEquals(userId, refundBill.getBuyerId(),
							"验证BuyerId");

					Logger.comment("校验Ymt_RefundProduct表");

					Logger.verifyEquals(orderId, refundPro.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals(salesRefundInfo.getRefundBillNo(),
							refundPro.getRefundBillNo(), "验证RefundBillNo");

					m.put("businessNo", salesRefundInfo.getRefundBillNo());

					// 查询交易退款结算表
					List<YmtSettlementInvoice> settlementInvoiceList = new YmtSettlementInvoiceWapper()
							.selectYmtSettlementInvoice(m);

					YmtSettlementInvoice refundSettlementInvoice = settlementInvoiceList
							.get(0);

					Logger.comment("校验Ymt_SettlementInvoice表");

					Logger.verifyEquals(salesRefundInfo.getRefundBillNo(),
							refundSettlementInvoice.getBusinessNo(),
							"验证BusinessNo");
					Logger.verifyEquals(2,
							refundSettlementInvoice.getBusinessType(),
							"验证BusinessType");
					Logger.verifyEquals(orderId,
							refundSettlementInvoice.getOrderId(), "验证OrderId");

					Logger.verifyEquals(
							refundBill.getRefundAmount().add(
									Utils.zeroIfNull(refundBill
											.getSettlementAmountOfCoupon())),
							refundSettlementInvoice.getTotalAmount(),
							"验证TotalAmount");

					Logger.verifyEquals(refundBill.getRefundAmount(),
							refundSettlementInvoice.getCashAmount(),
							"验证CashAmount");

					Logger.verifyEquals(sellerId,
							refundSettlementInvoice.getSellerId(), "验证SellerId");
					Logger.verifyEquals("退款结算",
							refundSettlementInvoice.getRemark(), "验证Remark");
					Logger.verifyEquals(1,
							refundSettlementInvoice.getSettlementStatus(),
							"验证SettlementStatus");
					Logger.verifyEquals(1,
							refundSettlementInvoice.getSettlementUser(),
							"验证SettlementUser");
					Logger.verifyEquals(null,
							refundSettlementInvoice.getProcessResult(),
							"验证ProcessResult");

					Logger.comment("校验ymt_orderinfo表");
					Logger.verifyEquals(
							10,
							(Integer) orderInfoList.get(i).get(
									"iProductRefundStatus"),
							"验证iProductRefundStatus");

				}

				Logger.comment("校验ymt_orders表");

				Logger.verifyEquals(17,
						(Integer) ymtOrders.get(0).get("iTradingStatus"),
						"验证iTradingStatus");
				Logger.verifyEquals(null,
						ymtOrders.get(0).get("iSalesRefundStatus"),
						"验证iSalesRefundStatus");

				m.remove("businessNo");
				m.put("businessType", 2);

				// 查询交易退款结算表
				List<YmtSettlementInvoice> settlementInvoiceList = new YmtSettlementInvoiceWapper()
						.selectYmtSettlementInvoice(m);

				Logger.comment("校验ymt_orderstate表");

				DataUtil.verifyDecimalEquals(
						settlementInvoiceList.stream()
								.map(account -> account.getCashAmount())
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountOfCash"),
						"验证fRefundedAmountOfCash");

				BigDecimal fRefundedAmountToAccount = Utils
						.zeroIfNull((BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountToAccount"));

				BigDecimal fRefundedPaidAmountToThirdParty = Utils
						.zeroIfNull((BigDecimal) ymtOrderState.get(0).get(
								"fRefundedPaidAmountToThirdParty"));

				BigDecimal fRefundedPrepaidAmount = Utils
						.zeroIfNull((BigDecimal) ymtOrderState.get(0).get(
								"fRefundedPrepaidAmount"));

				DataUtil.verifyDecimalEquals(
						fRefundedAmountToAccount.add(
								fRefundedPaidAmountToThirdParty).add(
								fRefundedPrepaidAmount),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountOfCash"),
						"验证fRefundedAmountOfCash");

				DataUtil.verifyDecimalEquals(fRefundedPrepaidAmount,
						PrepaidCardService
								.getCardEntry(userId, "TH0" + orderId),
						"校验取消订单退回的预付卡金额");

				BigDecimal afterAmount = AccountCallServiceV2
						.getAccountBalance(userId, 1);

				DataUtil.verifyDecimalEquals(fRefundedAmountToAccount,
						afterAmount.subtract(beforeAmount), "校验取消订单退回的资金账户金额");

			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SalesRefundSuccessRequest_030() {
		Logger.start(true, "使用了预付卡订单，余额+第三方支付宝组合支付。确认收货前,订单部分退款的金额小于余额支付的部分");
		try {

			PlaceOrderResp placeOrderResp = PrepaidCardService.placeOrder(true);

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId = placeOrderResp.getOrderList().get(0).getSellerId();
			int userId = placeOrderResp.getUserId();
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice = placeOrderResp.getPayAmount();// 支付金额

			OrderCallService orderCallService = new OrderCallService();

			// 用余额支付金额
			BigDecimal blanceAmout = new BigDecimal(47);
			// 支付订单 余额+支付宝组合支付
			// 13 为 app国际支付宝，15 微信
			String payType = "13";
			int thirdTradingId = new OrderCallService().orderPayRequest(userId,
					blanceAmout, tradingId, payType);

			new OrderCallService().orderPayCallBack(String
					.valueOf(thirdTradingId));

			// 等待支付网关异步处理
			Thread.sleep(2000);
			// 卖家接单
			orderCallService.acceptOrder(orderId, sellerId);
			// 申请退款
			ApplySalesRefundRequestBean applySalesRefund = new OrderCallService()
					.applySalesRefundRequestInJavaBean(orderId);

			applySalesRefund.getSalesRefundInfoList().remove(1);
			applySalesRefund.getSalesRefundInfoList().get(0)
					.setRefundAmount(blanceAmout.subtract(BigDecimal.TEN));

			new OrderCallService()
					.applySalesRefundRequestCall(applySalesRefund);

			salesrefundsuccessrequestBean.setOrderId(orderId);

			salesrefundsuccessrequestBean.setOperatorInfo("autotest");

			BigDecimal beforeAmount = AccountCallServiceV2.getAccountBalance(
					userId, 1);

			for (int i = 0; i < applySalesRefund.getSalesRefundInfoList()
					.size(); i++) {

				SalesRefundInfoBean salesRefundInfoBean = applySalesRefund
						.getSalesRefundInfoList().get(i);

				salesrefundsuccessrequestBean
						.setRefundBillNo(salesRefundInfoBean.getRefundBillNo());

				salesrefundsuccessrequestCall
						.setData(salesrefundsuccessrequestBean);

				Logger.comment(String.format("退该订单号 %s 第%s件商品", orderId, i + 1));
				salesrefundsuccessrequestCall.callService();

			}

			Logger.verifyEquals("ok",
					salesrefundsuccessrequestCall.getReturnData(), "验证退货退款成功返回");

			DefaultWapper defaultWapper = new DefaultWapper();
			if (salesrefundsuccessrequestCall.getReturnData().equals("ok")) {

				// 数据库验
				Map m = new HashMap();

				m.put("orderId", orderId);

				// 订单商品表
				List<Map> orderInfoList = defaultWapper
						.selectOrderInfoByOderId(orderId);
				// 订单主表
				List<Map> ymtOrders = defaultWapper
						.selectOrderByOderId(orderId);
				// ymtOrderState 表
				List<Map> ymtOrderState = defaultWapper
						.selectOrderStateByOderId(orderId);
				YmtRefundWapper ymtRefund = new YmtRefundWapper();

				// m.put("refundBillNo", refundBillNo);
				for (int i = 0; i < applySalesRefund.getSalesRefundInfoList()
						.size(); i++) {

					SalesRefundInfoBean salesRefundInfo = applySalesRefund
							.getSalesRefundInfoList().get(i);

					// 订单退货记录
					YmtRefundBill refundBill = ymtRefund.selectRefundBill(m)
							.get(i);
					// 退货的商品记录
					YmtRefundProduct refundPro = ymtRefund.selectRefundProduct(
							m).get(i);

					Logger.comment("校验订单号" + orderId + "第" + (i + 1) + "件商品");
					Logger.comment("校验Ymt_RefundBill表");
					Logger.verifyEquals(orderId, refundBill.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals(salesRefundInfo.getRefundBillNo(),
							refundBill.getRefundBillNo(), "验证RefundBillNo");

					DataUtil.verifyDecimalEquals(
							salesRefundInfo.getRefundAmount(),
							refundBill.getRefundAmount(), "验证refundAmount");

					Logger.verifyEquals(1, refundBill.getRefundStatus(),
							"验证RefundStatus");
					Logger.verifyEquals(1, refundBill.getSettlementStatus(),
							"验证SettlementStatus");
					Logger.verifyEquals(10, refundBill.getSalesRefundStatus(),
							"验证SalesRefundStatus");
					Logger.verifyEquals(1, refundBill.getRefundType(),
							"验证RefundType");

					Logger.verifyEquals(sellerId, refundBill.getSellerId(),
							"验证SellerId");
					Logger.verifyEquals(userId, refundBill.getBuyerId(),
							"验证BuyerId");

					Logger.comment("校验Ymt_RefundProduct表");

					Logger.verifyEquals(orderId, refundPro.getOrderId(),
							"验证OrderId");
					Logger.verifyEquals(salesRefundInfo.getRefundBillNo(),
							refundPro.getRefundBillNo(), "验证RefundBillNo");

					m.put("businessNo", salesRefundInfo.getRefundBillNo());

					// 查询交易退款结算表
					List<YmtSettlementInvoice> settlementInvoiceList = new YmtSettlementInvoiceWapper()
							.selectYmtSettlementInvoice(m);

					YmtSettlementInvoice refundSettlementInvoice = settlementInvoiceList
							.get(0);

					Logger.comment("校验Ymt_SettlementInvoice表");

					Logger.verifyEquals(salesRefundInfo.getRefundBillNo(),
							refundSettlementInvoice.getBusinessNo(),
							"验证BusinessNo");
					Logger.verifyEquals(2,
							refundSettlementInvoice.getBusinessType(),
							"验证BusinessType");
					Logger.verifyEquals(orderId,
							refundSettlementInvoice.getOrderId(), "验证OrderId");

					Logger.verifyEquals(
							refundBill.getRefundAmount().add(
									Utils.zeroIfNull(refundBill
											.getSettlementAmountOfCoupon())),
							refundSettlementInvoice.getTotalAmount(),
							"验证TotalAmount");

					Logger.verifyEquals(refundBill.getRefundAmount(),
							refundSettlementInvoice.getCashAmount(),
							"验证CashAmount");

					Logger.verifyEquals(sellerId,
							refundSettlementInvoice.getSellerId(), "验证SellerId");
					Logger.verifyEquals("退款结算",
							refundSettlementInvoice.getRemark(), "验证Remark");
					Logger.verifyEquals(1,
							refundSettlementInvoice.getSettlementStatus(),
							"验证SettlementStatus");
					Logger.verifyEquals(1,
							refundSettlementInvoice.getSettlementUser(),
							"验证SettlementUser");
					Logger.verifyEquals(null,
							refundSettlementInvoice.getProcessResult(),
							"验证ProcessResult");

					Logger.comment("校验ymt_orderinfo表");
					Logger.verifyEquals(
							10,
							(Integer) orderInfoList.get(i).get(
									"iProductRefundStatus"),
							"验证iProductRefundStatus");

				}

				Logger.comment("校验ymt_orders表");

				Logger.verifyEquals(17,
						(Integer) ymtOrders.get(0).get("iTradingStatus"),
						"验证iTradingStatus");
				Logger.verifyEquals(null,
						ymtOrders.get(0).get("iSalesRefundStatus"),
						"验证iSalesRefundStatus");

				m.remove("businessNo");
				m.put("businessType", 2);

				// 查询交易退款结算表
				List<YmtSettlementInvoice> settlementInvoiceList = new YmtSettlementInvoiceWapper()
						.selectYmtSettlementInvoice(m);

				Logger.comment("校验ymt_orderstate表");

				DataUtil.verifyDecimalEquals(
						settlementInvoiceList.stream()
								.map(account -> account.getCashAmount())
								.reduce(BigDecimal.ZERO, BigDecimal::add),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountOfCash"),
						"验证fRefundedAmountOfCash");

				BigDecimal fRefundedAmountToAccount = Utils
						.zeroIfNull((BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountToAccount"));

				BigDecimal fRefundedPaidAmountToThirdParty = Utils
						.zeroIfNull((BigDecimal) ymtOrderState.get(0).get(
								"fRefundedPaidAmountToThirdParty"));

				BigDecimal fRefundedPrepaidAmount = Utils
						.zeroIfNull((BigDecimal) ymtOrderState.get(0).get(
								"fRefundedPrepaidAmount"));

				DataUtil.verifyDecimalEquals(
						fRefundedAmountToAccount.add(
								fRefundedPaidAmountToThirdParty).add(
								fRefundedPrepaidAmount),
						(BigDecimal) ymtOrderState.get(0).get(
								"fRefundedAmountOfCash"),
						"验证fRefundedAmountOfCash");

				DataUtil.verifyDecimalEquals(fRefundedPrepaidAmount,
						PrepaidCardService
								.getCardEntry(userId, "TH0" + orderId),
						"校验取消订单退回的预付卡金额");

				BigDecimal afterAmount = AccountCallServiceV2
						.getAccountBalance(userId, 1);

				DataUtil.verifyDecimalEquals(fRefundedAmountToAccount,
						afterAmount.subtract(beforeAmount), "校验取消订单退回的资金账户金额");

			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}
